PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ unit_normal()

void unit_normal ( const POINT3D P1,
const POINT3D P2,
POINT3D normal 
)

Calculates the unit normal to two vectors, trying to avoid problems with over-narrow or over-wide cases.

Definition at line 510 of file lwgeodetic.c.

References cross_product(), dot_product(), normalize(), vector_difference(), and vector_sum().

Referenced by clairaut_cartesian(), edge_calculate_gbox(), edge_intersection(), edge_intersects(), test_sphere_project(), and vector_rotate().

511 {
512  double p_dot = dot_product(P1, P2);
513  POINT3D P3;
514 
515  /* If edge is really large, calculate a narrower equivalent angle A1/A3. */
516  if ( p_dot < 0 )
517  {
518  vector_sum(P1, P2, &P3);
519  normalize(&P3);
520  }
521  /* If edge is narrow, calculate a wider equivalent angle A1/A3. */
522  else if ( p_dot > 0.95 )
523  {
524  vector_difference(P2, P1, &P3);
525  normalize(&P3);
526  }
527  /* Just keep the current angle in A1/A3. */
528  else
529  {
530  P3 = *P2;
531  }
532 
533  /* Normals to the A-plane and B-plane */
534  cross_product(P1, &P3, normal);
535  normalize(normal);
536 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:584
static double dot_product(const POINT3D *p1, const POINT3D *p2)
Convert cartesian coordinates on unit sphere to lon/lat coordinates static void cart2ll(const POINT3D...
Definition: lwgeodetic.c:415
static void vector_difference(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the difference of two vectors.
Definition: lwgeodetic.c:445
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:434
static void cross_product(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the cross product of two vectors.
Definition: lwgeodetic.c:423
Here is the call graph for this function:
Here is the caller graph for this function: