PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lw_dist3d_ptarray_poly()

int lw_dist3d_ptarray_poly ( POINTARRAY pa,
LWPOLY poly,
PLANE3D plane,
DISTPTS3D dl 
)

Computes pointarray to polygon distance.

Definition at line 1300 of file measures3d.c.

1301 {
1302  uint32_t i, j, k;
1303  double f, s1, s2;
1304  VECTOR3D projp1_projp2;
1305  POINT3DZ p1, p2, projp1, projp2, intersectionp;
1306 
1307  getPoint3dz_p(pa, 0, &p1);
1308 
1309  /* the sign of s1 tells us on which side of the plane the point is. */
1310  s1 = project_point_on_plane(&p1, plane, &projp1);
1311  lw_dist3d_pt_poly(&p1, poly, plane, &projp1, dl);
1312  if ((s1 == 0.0) && (dl->distance < dl->tolerance))
1313  return LW_TRUE;
1314 
1315  for (i = 1; i < pa->npoints; i++)
1316  {
1317  int intersects;
1318  getPoint3dz_p(pa, i, &p2);
1319  s2 = project_point_on_plane(&p2, plane, &projp2);
1320  lw_dist3d_pt_poly(&p2, poly, plane, &projp2, dl);
1321  if ((s2 == 0.0) && (dl->distance < dl->tolerance))
1322  return LW_TRUE;
1323 
1324  /* If s1 and s2 has different signs that means they are on different sides of the plane of the polygon.
1325  * That means that the edge between the points crosses the plane and might intersect with the polygon */
1326  if ((s1 * s2) < 0)
1327  {
1328  /* The size of s1 and s2 is the distance from the point to the plane. */
1329  f = fabs(s1) / (fabs(s1) + fabs(s2));
1330  get_3dvector_from_points(&projp1, &projp2, &projp1_projp2);
1331 
1332  /* Get the point where the line segment crosses the plane */
1333  intersectionp.x = projp1.x + f * projp1_projp2.x;
1334  intersectionp.y = projp1.y + f * projp1_projp2.y;
1335  intersectionp.z = projp1.z + f * projp1_projp2.z;
1336 
1337  /* We set intersects to true until the opposite is proved */
1338  intersects = LW_TRUE;
1339 
1340  if (pt_in_ring_3d(&intersectionp, poly->rings[0], plane)) /*Inside outer ring*/
1341  {
1342  for (k = 1; k < poly->nrings; k++)
1343  {
1344  /* Inside a hole, so no intersection with the polygon*/
1345  if (pt_in_ring_3d(&intersectionp, poly->rings[k], plane))
1346  {
1347  intersects = LW_FALSE;
1348  break;
1349  }
1350  }
1351  if (intersects)
1352  {
1353  dl->distance = 0.0;
1354  dl->p1.x = intersectionp.x;
1355  dl->p1.y = intersectionp.y;
1356  dl->p1.z = intersectionp.z;
1357 
1358  dl->p2.x = intersectionp.x;
1359  dl->p2.y = intersectionp.y;
1360  dl->p2.z = intersectionp.z;
1361  return LW_TRUE;
1362  }
1363  }
1364  }
1365 
1366  projp1 = projp2;
1367  s1 = s2;
1368  p1 = p2;
1369  }
1370 
1371  /* check our pointarray against boundary and inner boundaries of the polygon */
1372  for (j = 0; j < poly->nrings; j++)
1373  lw_dist3d_ptarray_ptarray(pa, poly->rings[j], dl);
1374 
1375  return LW_TRUE;
1376 }
#define LW_FALSE
Definition: liblwgeom.h:109
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
Definition: lwgeom_api.c:216
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
int pt_in_ring_3d(const POINT3DZ *p, const POINTARRAY *ring, PLANE3D *plane)
pt_in_ring_3d(): crossing number test for a point in a polygon input: p = a point,...
Definition: measures3d.c:1574
static int get_3dvector_from_points(POINT3DZ *p1, POINT3DZ *p2, VECTOR3D *v)
Definition: measures3d.c:34
int lw_dist3d_pt_poly(POINT3DZ *p, LWPOLY *poly, PLANE3D *plane, POINT3DZ *projp, DISTPTS3D *dl)
Checking if the point projected on the plane of the polygon actually is inside that polygon.
Definition: measures3d.c:1258
double project_point_on_plane(POINT3DZ *p, PLANE3D *pl, POINT3DZ *p0)
Finds a point on a plane from where the original point is perpendicular to the plane.
Definition: measures3d.c:1531
int lw_dist3d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS3D *dl)
Finds all combinations of segments between two pointarrays.
Definition: measures3d.c:1088
POINT3DZ p2
Definition: measures3d.h:42
POINT3DZ p1
Definition: measures3d.h:41
double distance
Definition: measures3d.h:40
double tolerance
Definition: measures3d.h:47
POINTARRAY ** rings
Definition: liblwgeom.h:534
uint32_t nrings
Definition: liblwgeom.h:539
double z
Definition: liblwgeom.h:411
double x
Definition: liblwgeom.h:411
double y
Definition: liblwgeom.h:411
uint32_t npoints
Definition: liblwgeom.h:442
double z
Definition: measures3d.h:52
double x
Definition: measures3d.h:52
double y
Definition: measures3d.h:52

References DISTPTS3D::distance, get_3dvector_from_points(), getPoint3dz_p(), lw_dist3d_pt_poly(), lw_dist3d_ptarray_ptarray(), LW_FALSE, LW_TRUE, POINTARRAY::npoints, LWPOLY::nrings, DISTPTS3D::p1, DISTPTS3D::p2, project_point_on_plane(), pt_in_ring_3d(), LWPOLY::rings, DISTPTS3D::tolerance, POINT3DZ::x, VECTOR3D::x, POINT3DZ::y, VECTOR3D::y, POINT3DZ::z, and VECTOR3D::z.

Referenced by lw_dist3d_line_poly(), lw_dist3d_poly_poly(), and lw_dist3d_poly_tri().

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