PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ point_in_cone()

static int point_in_cone ( const POINT3D A1,
const POINT3D A2,
const POINT3D P 

Utility function for checking if P is within the cone defined by A1/A2.

Definition at line 3371 of file lwgeodetic.c.

References dot_product(), LW_FALSE, LW_TRUE, normalize(), and vector_sum().

Referenced by edge_intersects().

3372 {
3373  POINT3D AC; /* Center point of A1/A2 */
3374  double min_similarity, similarity;
3376  /* The normalized sum bisects the angle between start and end. */
3377  vector_sum(A1, A2, &AC);
3378  normalize(&AC);
3380  /* The projection of start onto the center defines the minimum similarity */
3381  min_similarity = dot_product(A1, &AC);
3383  /* The projection of candidate p onto the center */
3384  similarity = dot_product(P, &AC);
3386  /* If the point is more similar than the end, the point is in the cone */
3387  if ( similarity > min_similarity || fabs(similarity - min_similarity) < 2e-16 )
3388  {
3389  return LW_TRUE;
3390  }
3391  return LW_FALSE;
3392 }
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
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:434
Here is the call graph for this function:
Here is the caller graph for this function: