PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ define_plane()

int define_plane ( POINTARRAY pa,
PLANE3D pl 
)

Definition at line 1173 of file measures3d.c.

References FP_IS_ZERO, get_3dcross_product(), get_3dvector_from_points(), getPoint3dz_p(), POINTARRAY::npoints, PLANE3D::pop, PLANE3D::pv, VECTOR3D::x, POINT3DZ::x, VECTOR3D::y, POINT3DZ::y, VECTOR3D::z, and POINT3DZ::z.

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

1174 {
1175  const uint32_t POL_BREAKS = 3;
1176  uint32_t unique_points = pa->npoints - 1;
1177  uint32_t i;
1178 
1179  /* Calculate the average point */
1180  pl->pop.x = 0.0;
1181  pl->pop.y = 0.0;
1182  pl->pop.z = 0.0;
1183  for (i = 0; i < unique_points; i++)
1184  {
1185  POINT3DZ p;
1186  getPoint3dz_p(pa, i, &p);
1187  pl->pop.x += p.x;
1188  pl->pop.y += p.y;
1189  pl->pop.z += p.z;
1190  }
1191 
1192  pl->pop.x /= unique_points;
1193  pl->pop.y /= unique_points;
1194  pl->pop.z /= unique_points;
1195 
1196  pl->pv.x = 0.0;
1197  pl->pv.y = 0.0;
1198  pl->pv.z = 0.0;
1199  for (i = 0; i < POL_BREAKS; i++)
1200  {
1201  POINT3DZ point1, point2;
1202  VECTOR3D v1, v2, vp;
1203  uint32_t n1, n2;
1204  n1 = i * unique_points / POL_BREAKS;
1205  n2 = n1 + unique_points / POL_BREAKS; /* May overflow back to the first / last point */
1206 
1207  if (n1 == n2)
1208  continue;
1209 
1210  getPoint3dz_p(pa, n1, &point1);
1211  if (!get_3dvector_from_points(&pl->pop, &point1, &v1))
1212  continue;
1213 
1214  getPoint3dz_p(pa, n2, &point2);
1215  if (!get_3dvector_from_points(&pl->pop, &point2, &v2))
1216  continue;
1217 
1218  if (get_3dcross_product(&v1, &v2, &vp))
1219  {
1220  /* If the cross product isn't zero these 3 points aren't collinear
1221  * We divide by its lengthsq to normalize the additions */
1222  double vl = vp.x * vp.x + vp.y * vp.y + vp.z * vp.z;
1223  pl->pv.x += vp.x / vl;
1224  pl->pv.y += vp.y / vl;
1225  pl->pv.z += vp.z / vl;
1226  }
1227  }
1228 
1229  return (!FP_IS_ZERO(pl->pv.x) || !FP_IS_ZERO(pl->pv.y) || !FP_IS_ZERO(pl->pv.z));
1230 }
double z
Definition: liblwgeom.h:334
double y
Definition: liblwgeom.h:334
double x
Definition: liblwgeom.h:334
double z
Definition: measures3d.h:51
int npoints
Definition: liblwgeom.h:371
VECTOR3D pv
Definition: measures3d.h:58
#define FP_IS_ZERO(A)
double y
Definition: measures3d.h:51
unsigned int uint32_t
Definition: uthash.h:78
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:214
static int get_3dvector_from_points(POINT3DZ *p1, POINT3DZ *p2, VECTOR3D *v)
Definition: measures3d.c:45
POINT3DZ pop
Definition: measures3d.h:57
double x
Definition: measures3d.h:51
static int get_3dcross_product(VECTOR3D *v1, VECTOR3D *v2, VECTOR3D *v)
Definition: measures3d.c:55
Here is the call graph for this function:
Here is the caller graph for this function: