PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ point_in_cone()

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

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

Definition at line 3443 of file lwgeodetic.c.

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

Referenced by edge_intersects().

3444 {
3445  POINT3D AC; /* Center point of A1/A2 */
3446  double min_similarity, similarity;
3447 
3448  /* Boundary case */
3449  if (point3d_equals(A1, P) || point3d_equals(A2, P))
3450  return LW_TRUE;
3451 
3452  /* The normalized sum bisects the angle between start and end. */
3453  vector_sum(A1, A2, &AC);
3454  normalize(&AC);
3455 
3456  /* The projection of start onto the center defines the minimum similarity */
3457  min_similarity = dot_product(A1, &AC);
3458 
3459  /* If the edge is sufficiently curved, use the dot product test */
3460  if (fabs(1.0 - min_similarity) > 1e-10)
3461  {
3462  /* The projection of candidate p onto the center */
3463  similarity = dot_product(P, &AC);
3464 
3465  /* If the projection of the candidate is larger than */
3466  /* the projection of the start point, the candidate */
3467  /* must be closer to the center than the start, so */
3468  /* therefor inside the cone */
3469  if (similarity > min_similarity)
3470  {
3471  return LW_TRUE;
3472  }
3473  else
3474  {
3475  return LW_FALSE;
3476  }
3477  }
3478  else
3479  {
3480  /* Where the edge is very narrow, the dot product test */
3481  /* fails, but we can use the almost-planar nature of the */
3482  /* problem space then to test if the vector from the */
3483  /* candidate to the start point in a different direction */
3484  /* to the vector from candidate to end point */
3485  /* If so, then candidate is between start and end */
3486  POINT3D PA1, PA2;
3487  vector_difference(P, A1, &PA1);
3488  vector_difference(P, A2, &PA2);
3489  normalize(&PA1);
3490  normalize(&PA2);
3491  if (dot_product(&PA1, &PA2) < 0.0)
3492  {
3493  return LW_TRUE;
3494  }
3495  else
3496  {
3497  return LW_FALSE;
3498  }
3499  }
3500  return LW_FALSE;
3501 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:611
static int point3d_equals(const POINT3D *p1, const POINT3D *p2)
Utility function for ptarray_contains_point_sphere()
Definition: lwgeodetic.c:42
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:442
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
static void vector_difference(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the difference of two vectors.
Definition: lwgeodetic.c:472
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:461
Here is the call graph for this function:
Here is the caller graph for this function: