PostGIS  2.4.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 1077 of file measures3d.c.

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

Referenced by lw_dist3d_line_poly(), and lw_dist3d_poly_poly().

1078 {
1079 
1080 
1081  int i,j,k;
1082  double f, s1, s2;
1083  VECTOR3D projp1_projp2;
1084  POINT3DZ p1, p2,projp1, projp2, intersectionp;
1085 
1086  getPoint3dz_p(pa, 0, &p1);
1087 
1089  &p1, plane, &projp1); /*the sign of s1 tells us on which side of the plane the point is. */
1090  lw_dist3d_pt_poly(&p1, poly, plane,&projp1, dl);
1091  if ((s1 == 0.0) && (dl->distance < dl->tolerance))
1092  {
1093  return LW_TRUE;
1094  }
1095 
1096  for (i=1;i<pa->npoints;i++)
1097  {
1098  int intersects;
1099  getPoint3dz_p(pa, i, &p2);
1100  s2=project_point_on_plane(&p2, plane, &projp2);
1101  lw_dist3d_pt_poly(&p2, poly, plane,&projp2, dl);
1102  if ((s2 == 0.0) && (dl->distance < dl->tolerance))
1103  {
1104  return LW_TRUE;
1105  }
1106 
1107  /*If s1and s2 has different signs that means they are on different sides of the plane of the polygon.
1108  That means that the edge between the points crosses the plane and might intersect with the polygon*/
1109  if ((s1 * s2) < 0)
1110  {
1111  f=fabs(s1)/(fabs(s1)+fabs(s2)); /*The size of s1 and s2 is the distance from the point to the plane.*/
1112  get_3dvector_from_points(&projp1, &projp2,&projp1_projp2);
1113 
1114  /*get the point where the line segment crosses the plane*/
1115  intersectionp.x=projp1.x+f*projp1_projp2.x;
1116  intersectionp.y=projp1.y+f*projp1_projp2.y;
1117  intersectionp.z=projp1.z+f*projp1_projp2.z;
1118 
1119  intersects = LW_TRUE; /*We set intersects to true until the opposite is proved*/
1120 
1121  if(pt_in_ring_3d(&intersectionp, poly->rings[0], plane)) /*Inside outer ring*/
1122  {
1123  for (k=1;k<poly->nrings; k++)
1124  {
1125  /* Inside a hole, so no intersection with the polygon*/
1126  if ( pt_in_ring_3d(&intersectionp, poly->rings[k], plane ))
1127  {
1128  intersects=LW_FALSE;
1129  break;
1130  }
1131  }
1132  if(intersects)
1133  {
1134  dl->distance=0.0;
1135  dl->p1.x=intersectionp.x;
1136  dl->p1.y=intersectionp.y;
1137  dl->p1.z=intersectionp.z;
1138 
1139  dl->p2.x=intersectionp.x;
1140  dl->p2.y=intersectionp.y;
1141  dl->p2.z=intersectionp.z;
1142  return LW_TRUE;
1143 
1144  }
1145  }
1146  }
1147 
1148  projp1=projp2;
1149  s1=s2;
1150  p1=p2;
1151  }
1152 
1153  /*check or pointarray against boundary and inner boundaries of the polygon*/
1154  for (j=0;j<poly->nrings;j++)
1155  {
1156  lw_dist3d_ptarray_ptarray(pa, poly->rings[j], dl);
1157  }
1158 
1159 return LW_TRUE;
1160 }
double z
Definition: liblwgeom.h:334
double y
Definition: liblwgeom.h:334
double distance
Definition: measures3d.h:41
double x
Definition: liblwgeom.h:334
double z
Definition: measures3d.h:51
POINT3DZ p2
Definition: measures3d.h:43
int npoints
Definition: liblwgeom.h:371
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:1237
POINT3DZ p1
Definition: measures3d.h:42
double y
Definition: measures3d.h:51
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:1043
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:214
#define LW_FALSE
Definition: liblwgeom.h:77
Datum intersects(PG_FUNCTION_ARGS)
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
POINTARRAY ** rings
Definition: liblwgeom.h:457
static int get_3dvector_from_points(POINT3DZ *p1, POINT3DZ *p2, VECTOR3D *v)
Definition: measures3d.c:45
int nrings
Definition: liblwgeom.h:455
double tolerance
Definition: measures3d.h:46
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, pa = vertex points of a ring V[n+1] with V[n]=V[0] plane=the plane that the vertex points are lying on returns: 0 = outside, 1 = inside
Definition: measures3d.c:1283
double x
Definition: measures3d.h:51
int lw_dist3d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2, DISTPTS3D *dl)
Finds all combinationes of segments between two pointarrays.
Definition: measures3d.c:867
Here is the call graph for this function:
Here is the caller graph for this function: