PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lw_dist3d_ptarray_tri()

int lw_dist3d_ptarray_tri ( const POINTARRAY pa,
const LWTRIANGLE tri,
PLANE3D plane,
DISTPTS3D dl 
)

Computes pointarray to triangle distance.

Definition at line 1413 of file measures3d.c.

1414 {
1415  uint32_t i;
1416  double f, s1, s2;
1417  VECTOR3D projp1_projp2;
1418  POINT3DZ p1, p2, projp1, projp2, intersectionp;
1419 
1420  getPoint3dz_p(pa, 0, &p1);
1421 
1422  /* the sign of s1 tells us on which side of the plane the point is. */
1423  s1 = project_point_on_plane(&p1, plane, &projp1);
1424  lw_dist3d_pt_tri(&p1, tri, plane, &projp1, dl);
1425  if ((s1 == 0.0) && (dl->distance < dl->tolerance))
1426  return LW_TRUE;
1427 
1428  for (i = 1; i < pa->npoints; i++)
1429  {
1430  int intersects;
1431  getPoint3dz_p(pa, i, &p2);
1432  s2 = project_point_on_plane(&p2, plane, &projp2);
1433  lw_dist3d_pt_tri(&p2, tri, plane, &projp2, dl);
1434  if ((s2 == 0.0) && (dl->distance < dl->tolerance))
1435  return LW_TRUE;
1436 
1437  /* If s1 and s2 has different signs that means they are on different sides of the plane of the triangle.
1438  * That means that the edge between the points crosses the plane and might intersect with the triangle
1439  */
1440  if ((s1 * s2) < 0)
1441  {
1442  /* The size of s1 and s2 is the distance from the point to the plane. */
1443  f = fabs(s1) / (fabs(s1) + fabs(s2));
1444  get_3dvector_from_points(&projp1, &projp2, &projp1_projp2);
1445 
1446  /* Get the point where the line segment crosses the plane */
1447  intersectionp.x = projp1.x + f * projp1_projp2.x;
1448  intersectionp.y = projp1.y + f * projp1_projp2.y;
1449  intersectionp.z = projp1.z + f * projp1_projp2.z;
1450 
1451  /* We set intersects to true until the opposite is proved */
1452  intersects = LW_TRUE;
1453 
1454  if (pt_in_ring_3d(&intersectionp, tri->points, plane)) /*Inside outer ring*/
1455  {
1456  if (intersects)
1457  {
1458  dl->distance = 0.0;
1459  dl->p1.x = intersectionp.x;
1460  dl->p1.y = intersectionp.y;
1461  dl->p1.z = intersectionp.z;
1462 
1463  dl->p2.x = intersectionp.x;
1464  dl->p2.y = intersectionp.y;
1465  dl->p2.z = intersectionp.z;
1466  return LW_TRUE;
1467  }
1468  }
1469  }
1470 
1471  projp1 = projp2;
1472  s1 = s2;
1473  p1 = p2;
1474  }
1475 
1476  /* check our pointarray against triangle contour */
1477  lw_dist3d_ptarray_ptarray(pa, tri->points, dl);
1478  return LW_TRUE;
1479 }
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
Definition: lwgeom_api.c:215
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
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:1573
static int get_3dvector_from_points(const POINT3DZ *p1, const POINT3DZ *p2, VECTOR3D *v)
Definition: measures3d.c:34
static double project_point_on_plane(const 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:57
int lw_dist3d_ptarray_ptarray(const POINTARRAY *l1, const POINTARRAY *l2, DISTPTS3D *dl)
Finds all combinations of segments between two pointarrays.
Definition: measures3d.c:1122
int lw_dist3d_pt_tri(const POINT3DZ *p, const LWTRIANGLE *tri, PLANE3D *plane, POINT3DZ *projp, DISTPTS3D *dl)
Definition: measures3d.c:1317
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 * points
Definition: liblwgeom.h:495
double z
Definition: liblwgeom.h:396
double x
Definition: liblwgeom.h:396
double y
Definition: liblwgeom.h:396
uint32_t npoints
Definition: liblwgeom.h:427
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_tri(), lw_dist3d_ptarray_ptarray(), LW_TRUE, POINTARRAY::npoints, DISTPTS3D::p1, DISTPTS3D::p2, LWTRIANGLE::points, project_point_on_plane(), pt_in_ring_3d(), DISTPTS3D::tolerance, POINT3DZ::x, VECTOR3D::x, POINT3DZ::y, VECTOR3D::y, POINT3DZ::z, and VECTOR3D::z.

Referenced by lw_dist3d_line_tri(), lw_dist3d_poly_tri(), and lw_dist3d_tri_tri().

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