PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ define_plane()

int define_plane ( POINTARRAY pa,
PLANE3D pl 
)

Definition at line 1167 of file measures3d.c.

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

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

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

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