PostGIS  2.4.9dev-r@@SVN_REVISION@@

## ◆ edge_intersects()

 int edge_intersects ( const POINT3D * A1, const POINT3D * A2, const POINT3D * B1, const POINT3D * B2 )

Returns non-zero if edges A and B interact.

The type of interaction is given in the return value with the bitmask elements defined above.

Definition at line 3525 of file lwgeodetic.c.

3526 {
3527  POINT3D AN, BN, VN; /* Normals to plane A and plane B */
3528  double ab_dot;
3529  int a1_side, a2_side, b1_side, b2_side;
3530  int rv = PIR_NO_INTERACT;
3531
3532  /* Normals to the A-plane and B-plane */
3533  unit_normal(A1, A2, &AN);
3534  unit_normal(B1, B2, &BN);
3535
3536  /* Are A-plane and B-plane basically the same? */
3537  ab_dot = dot_product(&AN, &BN);
3538
3539  if ( FP_EQUALS(fabs(ab_dot), 1.0) )
3540  {
3541  /* Co-linear case */
3542  if ( point_in_cone(A1, A2, B1) || point_in_cone(A1, A2, B2) ||
3543  point_in_cone(B1, B2, A1) || point_in_cone(B1, B2, A2) )
3544  {
3545  rv |= PIR_INTERSECTS;
3546  rv |= PIR_COLINEAR;
3547  }
3548  return rv;
3549  }
3550
3551  /* What side of plane-A and plane-B do the end points */
3552  /* of A and B fall? */
3553  a1_side = dot_product_side(&BN, A1);
3554  a2_side = dot_product_side(&BN, A2);
3555  b1_side = dot_product_side(&AN, B1);
3556  b2_side = dot_product_side(&AN, B2);
3557
3558  /* Both ends of A on the same side of plane B. */
3559  if ( a1_side == a2_side && a1_side != 0 )
3560  {
3561  /* No intersection. */
3562  return PIR_NO_INTERACT;
3563  }
3564
3565  /* Both ends of B on the same side of plane A. */
3566  if ( b1_side == b2_side && b1_side != 0 )
3567  {
3568  /* No intersection. */
3569  return PIR_NO_INTERACT;
3570  }
3571
3573  if ( a1_side != a2_side && (a1_side + a2_side) == 0 &&
3574  b1_side != b2_side && (b1_side + b2_side) == 0 )
3575  {
3576  /* Have to check if intersection point is inside both arcs */
3577  unit_normal(&AN, &BN, &VN);
3578  if ( point_in_cone(A1, A2, &VN) && point_in_cone(B1, B2, &VN) )
3579  {
3580  return PIR_INTERSECTS;
3581  }
3582
3583  /* Have to check if intersection point is inside both arcs */
3584  vector_scale(&VN, -1);
3585  if ( point_in_cone(A1, A2, &VN) && point_in_cone(B1, B2, &VN) )
3586  {
3587  return PIR_INTERSECTS;
3588  }
3589
3590  return PIR_NO_INTERACT;
3591  }
3592
3593  /* The rest are all intersects variants... */
3594  rv |= PIR_INTERSECTS;
3595
3596  /* A touches B */
3597  if ( a1_side == 0 )
3598  {
3599  /* Touches at A1, A2 is on what side? */
3600  rv |= (a2_side < 0 ? PIR_A_TOUCH_RIGHT : PIR_A_TOUCH_LEFT);
3601  }
3602  else if ( a2_side == 0 )
3603  {
3604  /* Touches at A2, A1 is on what side? */
3605  rv |= (a1_side < 0 ? PIR_A_TOUCH_RIGHT : PIR_A_TOUCH_LEFT);
3606  }
3607
3608  /* B touches A */
3609  if ( b1_side == 0 )
3610  {
3611  /* Touches at B1, B2 is on what side? */
3612  rv |= (b2_side < 0 ? PIR_B_TOUCH_RIGHT : PIR_B_TOUCH_LEFT);
3613  }
3614  else if ( b2_side == 0 )
3615  {
3616  /* Touches at B2, B1 is on what side? */
3617  rv |= (b1_side < 0 ? PIR_B_TOUCH_RIGHT : PIR_B_TOUCH_LEFT);
3618  }
3619
3620  return rv;
3621 }
#define PIR_B_TOUCH_RIGHT
Definition: lwgeodetic.h:91
#define PIR_A_TOUCH_RIGHT
Definition: lwgeodetic.h:89
static int dot_product_side(const POINT3D *p, const POINT3D *q)
Utility function for edge_intersects(), signum with a tolerance in determining if the value is zero...
Definition: lwgeodetic.c:3510
#define PIR_A_TOUCH_LEFT
Definition: lwgeodetic.h:90
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 cas...
Definition: lwgeodetic.c:537
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
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: lwgeodetic.c:3443
#define FP_EQUALS(A, B)
#define PIR_NO_INTERACT
Bitmask elements for edge_intersects() return value.
Definition: lwgeodetic.h:86
#define PIR_B_TOUCH_LEFT
Definition: lwgeodetic.h:92
#define PIR_COLINEAR
Definition: lwgeodetic.h:88
#define PIR_INTERSECTS
Definition: lwgeodetic.h:87
void vector_scale(POINT3D *n, double scale)
Scale a vector out by a factor.
Definition: lwgeodetic.c:483
Here is the call graph for this function:
Here is the caller graph for this function: