chiark / gitweb /
really edgewise vertex displacement - new calculations, experimental
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Sun, 12 Oct 2008 19:39:51 +0000 (20:39 +0100)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Sun, 12 Oct 2008 19:39:51 +0000 (20:39 +0100)
energy.c
minimise.h

index 9bd66e3..19f32e2 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -36,27 +36,22 @@ static const CostContribution costs[]= {
 
 #if XBITS==3
 #define STOP_EPSILON 1e-6
-    COST(  3e3,   line_bending_cost)
-    COST(  3e3,   edge_length_variation_cost)
+    COST(  3e3,   vertex_displacement_cost)
     COST( 0.4e3,  rim_proximity_cost)
-    COST(  1e6,   edge_angle_cost)
-                  #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.7)
-//    COST(  1e1,   small_triangles_cost)
+    COST(  1e7,   edge_angle_cost)
+                  #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.2/1.7)
+    COST(  1e2,   small_triangles_cost)
     COST(  1e12,   noncircular_rim_cost)
 #endif
 
 #if XBITS==4
 #define STOP_EPSILON 1.2e-4
-    COST(  3e5,   line_bending_cost)
-    COST( 10e3,   edge_length_variation_cost)
-    COST( 9.0e3,  rim_proximity_cost) // 5e1 is too much
-                                     // 2.5e1 is too little
-    // 0.2e1 grows compared to previous ?
-    // 0.6e0 shrinks compared to previous ?
-
-//    COST(  1e12,   edge_angle_cost)
-                  #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.3)
-    COST(  1e18,   noncircular_rim_cost)
+    COST(  3e3,   vertex_displacement_cost)
+    COST( 0.2e3,  rim_proximity_cost)
+//    COST(  1e6,   edge_angle_cost)
+                  #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.7)
+//    COST(  1e1,   small_triangles_cost)
+    COST(  1e12,   noncircular_rim_cost)
 #endif
 
 #if XBITS==5
@@ -218,7 +213,47 @@ void compute_vertex_areas(const Vertices vertices, int section) {
   }
 }
 
-/*---------- Edgewise vertex displacement ----------*/
+/*---------- combined vertex displacement ----------*/
+
+  /*
+   *   At vertex Q considering edge direction e to R
+   *   and corresponding opposite edge to P.
+   *
+   *   Let  R' = Q + PQ
+   *        D  = R' - R
+   *                                                             delta
+   *              [       -1                                    ]
+   *   cost    =  [ lambda  . ( D . PQ/|PQ| ) + | D x PQ/|PQ| | ]
+   *       Q,e    [ ------------------------------------------- ]
+   *              [                      |PQ|                   ]
+   */
+
+double vertex_displacement_cost(const Vertices vertices, int section) {
+  const double inv_lambda= 1.0/1; //2;
+  const double delta= 4;
+  const double pqlen2_epsilon= 1e-12;
+
+  int pi,e,qi,ri, k;
+  double pq[D3], d[D3], ddot, dcross[D3];
+  double total_cost= 0;
+
+  FOR_EDGE(qi,e,ri, OUTER) {
+    pi= EDGE_END2(qi,(e+3)%V6); if (pi<0) continue;
+
+    K pq[k]= -vertices[pi][k] + vertices[qi][k];
+    K d[k]= vertices[qi][k] + pq[k] - vertices[ri][k];
+    ddot= dotprod(d,pq);
+    xprod(dcross, d,pq);
+    double pqlen2= magnD2(pq);
+    double cost_basis= inv_lambda * ddot + magnD(dcross);
+    double cost= pow(cost_basis / (pqlen2 + pqlen2_epsilon), delta);
+
+    total_cost += cost;
+  }
+  return total_cost;
+}
+
+/*---------- at-vertex edge angles ----------*/
 
   /*
    * Definition:
@@ -315,6 +350,8 @@ double edge_length_variation_cost(const Vertices vertices, int section) {
    */
 
 double prop_edge_length_variation_cost(const Vertices vertices, int section) {
+  const double num_epsilon= 1e-6;
+
   double cost= 0, exponent_r= 2;
   int q, e,r, eback;
 
@@ -324,7 +361,7 @@ double prop_edge_length_variation_cost(const Vertices vertices, int section) {
     double leback= edge_lengths[q][eback];
     double diff= le - leback;
     double num= MIN(le, leback);
-    cost += pow(diff / (num + 1e-6), exponent_r);
+    cost += pow(diff / (num + num_epsilon), exponent_r);
   }
   return cost;
 }
index c611b89..f75bc57 100644 (file)
@@ -20,6 +20,7 @@ extern double vertex_areas[N], vertex_mean_edge_lengths[N], edge_lengths[N][V6];
 
 extern const double edge_angle_cost_circcircrat;
 
+double vertex_displacement_cost(const Vertices vertices, int section);
 double line_bending_cost(const Vertices vertices, int section);
 double noncircular_rim_cost(const Vertices vertices, int section);
 double edge_length_variation_cost(const Vertices vertices, int section);