CU_ASSERT_DOUBLE_EQUAL(dir2, -2.35612, 0.0001);
}
+#if 0
+/**
+* Tests the relative numerical stability of the "robust" and
+* naive cross product calculation methods.
+*/
+static void cross_product_stability(void)
+{
+ POINT2D p1, p2;
+ int i;
+ GEOGRAPHIC_POINT g1, g2;
+ POINT3D A1, A2;
+ POINT3D Nr, Nc;
+ POINT3D Or, Oc;
+
+ p1.x = 10.0;
+ p1.y = 45.0;
+ p2.x = 10.0;
+ p2.y = 50.0;
+
+ geographic_point_init(p1.x, p1.y, &g1);
+ ll2cart(&p1, &A1);
+
+ for ( i = 0; i < 40; i++ )
+ {
+ geographic_point_init(p2.x, p2.y, &g2);
+ ll2cart(&p2, &A2);
+
+ /* Skea */
+ robust_cross_product(&g1, &g2, &Nr);
+ normalize(&Nr);
+
+ /* Ramsey */
+ unit_normal(&A1, &A2, &Nc);
+
+ if ( i > 0 )
+ {
+ printf("\n- %d -------------------- %.24g ------------------------\n", i, p2.y);
+ printf("Skea: %.24g,%.24g,%.24g\n", Nr.x, Nr.y, Nr.z);
+ printf("Skea Diff: %.24g,%.24g,%.24g\n", Or.x-Nr.x, Or.y-Nr.y, Or.z-Nr.z);
+ printf("Ramsey: %.24g,%.24g,%.24g\n", Nc.x, Nc.y, Nc.z);
+ printf("Ramsey Diff: %.24g,%.24g,%.24g\n", Oc.x-Nc.x, Oc.y-Nc.y, Oc.z-Nc.z);
+ printf("Diff: %.24g,%.24g,%.24g\n", Nr.x-Nc.x, Nr.y-Nc.y, Nr.z-Nc.z);
+ }
+
+ Or = Nr;
+ Oc = Nc;
+
+ p2.y += (p1.y - p2.y)/2.0;
+ }
+}
+#endif
+
static void test_gbox_from_spherical_coordinates(void)
{
#if RANDOM_TEST
printf("line %d: diff %.9g\n", i, fabs(gbox.xmin - gbox_slow.xmin)+fabs(gbox.ymin - gbox_slow.ymin)+fabs(gbox.zmin - gbox_slow.zmin));
printf("------------\n");
#endif
- CU_ASSERT_DOUBLE_EQUAL(gbox.xmin, gbox_slow.xmin, 0.000001);
- CU_ASSERT_DOUBLE_EQUAL(gbox.ymin, gbox_slow.ymin, 0.000001);
- CU_ASSERT_DOUBLE_EQUAL(gbox.zmin, gbox_slow.zmin, 0.000001);
- CU_ASSERT_DOUBLE_EQUAL(gbox.xmax, gbox_slow.xmax, 0.000001);
- CU_ASSERT_DOUBLE_EQUAL(gbox.ymax, gbox_slow.ymax, 0.000001);
- CU_ASSERT_DOUBLE_EQUAL(gbox.zmax, gbox_slow.zmax, 0.000001);
+ CU_ASSERT_DOUBLE_EQUAL(gbox.xmin, gbox_slow.xmin, 0.00000001);
+ CU_ASSERT_DOUBLE_EQUAL(gbox.ymin, gbox_slow.ymin, 0.00000001);
+ CU_ASSERT_DOUBLE_EQUAL(gbox.zmin, gbox_slow.zmin, 0.00000001);
+ CU_ASSERT_DOUBLE_EQUAL(gbox.xmax, gbox_slow.xmax, 0.00000001);
+ CU_ASSERT_DOUBLE_EQUAL(gbox.ymax, gbox_slow.ymax, 0.00000001);
+ CU_ASSERT_DOUBLE_EQUAL(gbox.zmax, gbox_slow.zmax, 0.00000001);
}
}
/**
* Convert lon/lat coordinates to cartesion coordinates on unit sphere
*/
-static void ll2cart(const POINT2D *g, POINT3D *p)
+void ll2cart(const POINT2D *g, POINT3D *p)
{
double x_rad = M_PI * g->x / 180.0;
double y_rad = M_PI * g->y / 180.0;
/**
* Convert cartesion coordinates on unit sphere to lon/lat coordinates
-*/
static void cart2ll(const POINT3D *p, POINT2D *g)
{
g->x = longitude_degrees_normalize(180.0 * atan2(p->y, p->x) / M_PI);
g->y = latitude_degrees_normalize(180.0 * asin(p->z) / M_PI);
}
+*/
/**
* Calculate the dot product of two unit vectors
* Calculates the unit normal to two vectors, trying to avoid
* problems with over-narrow or over-wide cases.
*/
-static void unit_normal(const POINT3D *P1, const POINT3D *P2, POINT3D *normal)
+void unit_normal(const POINT3D *P1, const POINT3D *P2, POINT3D *normal)
{
double p_dot = dot_product(P1, P2);
POINT3D P3;