PostGIS  3.3.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 3299 of file lwgeodetic.c.

3300 {
3301  POINT3D AC; /* Center point of A1/A2 */
3302  double min_similarity, similarity;
3303 
3304  /* Boundary case */
3305  if (point3d_equals(A1, P) || point3d_equals(A2, P))
3306  return LW_TRUE;
3307 
3308  /* The normalized sum bisects the angle between start and end. */
3309  vector_sum(A1, A2, &AC);
3310  normalize(&AC);
3311 
3312  /* The projection of start onto the center defines the minimum similarity */
3313  min_similarity = dot_product(A1, &AC);
3314 
3315  /* If the edge is sufficiently curved, use the dot product test */
3316  if (fabs(1.0 - min_similarity) > 1e-10)
3317  {
3318  /* The projection of candidate p onto the center */
3319  similarity = dot_product(P, &AC);
3320 
3321  /* If the projection of the candidate is larger than */
3322  /* the projection of the start point, the candidate */
3323  /* must be closer to the center than the start, so */
3324  /* therefor inside the cone */
3325  if (similarity > min_similarity)
3326  {
3327  return LW_TRUE;
3328  }
3329  else
3330  {
3331  return LW_FALSE;
3332  }
3333  }
3334  else
3335  {
3336  /* Where the edge is very narrow, the dot product test */
3337  /* fails, but we can use the almost-planar nature of the */
3338  /* problem space then to test if the vector from the */
3339  /* candidate to the start point in a different direction */
3340  /* to the vector from candidate to end point */
3341  /* If so, then candidate is between start and end */
3342  POINT3D PA1, PA2;
3343  vector_difference(P, A1, &PA1);
3344  vector_difference(P, A2, &PA2);
3345  normalize(&PA1);
3346  normalize(&PA2);
3347  if (dot_product(&PA1, &PA2) < 0.0)
3348  {
3349  return LW_TRUE;
3350  }
3351  else
3352  {
3353  return LW_FALSE;
3354  }
3355  }
3356  return LW_FALSE;
3357 }
#define LW_FALSE
Definition: liblwgeom.h:109
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:615
static void vector_difference(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the difference of two vectors.
Definition: lwgeodetic.c:476
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:446
void vector_sum(const POINT3D *a, const POINT3D *b, POINT3D *n)
Calculate the sum of two vectors.
Definition: lwgeodetic.c:465
static int point3d_equals(const POINT3D *p1, const POINT3D *p2)
Utility function for ptarray_contains_point_sphere()
Definition: lwgeodetic.c:42

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

Referenced by edge_intersects().

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