PostGIS  2.1.10dev-r@@SVN_REVISION@@
 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 490 of file lwgeodetic.c.

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

491 {
492  double p_dot = dot_product(P1, P2);
493  POINT3D P3;
494
495  /* If edge is really large, calculate a narrower equivalent angle A1/A3. */
496  if ( p_dot < 0 )
497  {
498  vector_sum(P1, P2, &P3);
499  normalize(&P3);
500  }
501  /* If edge is narrow, calculate a wider equivalent angle A1/A3. */
502  else if ( p_dot > 0.95 )
503  {
504  vector_difference(P2, P1, &P3);
505  normalize(&P3);
506  }
507  /* Just keep the current angle in A1/A3. */
508  else
509  {
510  P3 = *P2;
511  }
512
513  /* Normals to the A-plane and B-plane */
514  cross_product(P1, &P3, normal);
515  normalize(normal);
516 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:564
static double dot_product(const POINT3D *p1, const POINT3D *p2)
Convert cartesion coordinates on unit sphere to lon/lat coordinates static void cart2ll(const POINT3D...
Definition: lwgeodetic.c:397
static void vector_difference(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the difference of two vectors.
Definition: lwgeodetic.c:427
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:416
static void cross_product(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the cross product of two vectors.
Definition: lwgeodetic.c:405

Here is the call graph for this function: Here is the caller graph for this function: 