static char * test_length() { Vector3D vector = vector3d(3.0, 4.0, 12.0); double length = vector3d_length(vector); mu_assert(length == 13, "Error: Vector3D length not correct"); return 0; }
static char * test_unit() { Vector3D vector = vector3d(3.0, 4.0, 0.0); Vector3D unit = vector3d_unit(vector); double newLen = vector3d_length(unit); mu_assert(newLen == 1, "Error: Vector3D is not unit"); return 0; }
float8 spoint_dist ( const SPoint * p1, const SPoint * p2 ) { float8 dl = p1->lng - p2->lng; float8 f = ( ( sin( p1->lat )*sin( p2->lat ) + cos( p1->lat )*cos( p2->lat )*cos( dl ) ) ); if( FPeq( f, 1.0 ) ){ /* for small distances */ Vector3D v1, v2, v3; spoint_vector3d(&v1, p1); spoint_vector3d(&v2, p2); vector3d_cross( &v3, &v1, &v2 ); f = vector3d_length(&v3); } else { f = acos(f); } if ( FPzero(f) ){ return 0.0; } else { return f; } }