PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ define_plane()

int define_plane ( POINTARRAY pa,
PLANE3D pl 
)

Definition at line 1448 of file measures3d.c.

1449 {
1450  const uint32_t POL_BREAKS = 3;
1451 
1452  assert(pa);
1453  assert(pa->npoints > 3);
1454  if (!pa)
1455  return LW_FALSE;
1456 
1457  uint32_t unique_points = pa->npoints - 1;
1458  uint32_t i;
1459 
1460  if (pa->npoints < 3)
1461  return LW_FALSE;
1462 
1463  /* Calculate the average point */
1464  pl->pop.x = 0.0;
1465  pl->pop.y = 0.0;
1466  pl->pop.z = 0.0;
1467  for (i = 0; i < unique_points; i++)
1468  {
1469  POINT3DZ p;
1470  getPoint3dz_p(pa, i, &p);
1471  pl->pop.x += p.x;
1472  pl->pop.y += p.y;
1473  pl->pop.z += p.z;
1474  }
1475 
1476  pl->pop.x /= unique_points;
1477  pl->pop.y /= unique_points;
1478  pl->pop.z /= unique_points;
1479 
1480  pl->pv.x = 0.0;
1481  pl->pv.y = 0.0;
1482  pl->pv.z = 0.0;
1483  for (i = 0; i < POL_BREAKS; i++)
1484  {
1485  POINT3DZ point1, point2;
1486  VECTOR3D v1, v2, vp;
1487  uint32_t n1, n2;
1488  n1 = i * unique_points / POL_BREAKS;
1489  n2 = n1 + unique_points / POL_BREAKS; /* May overflow back to the first / last point */
1490 
1491  if (n1 == n2)
1492  continue;
1493 
1494  getPoint3dz_p(pa, n1, &point1);
1495  if (!get_3dvector_from_points(&pl->pop, &point1, &v1))
1496  continue;
1497 
1498  getPoint3dz_p(pa, n2, &point2);
1499  if (!get_3dvector_from_points(&pl->pop, &point2, &v2))
1500  continue;
1501 
1502  if (get_3dcross_product(&v1, &v2, &vp))
1503  {
1504  /* If the cross product isn't zero these 3 points aren't collinear
1505  * We divide by its lengthsq to normalize the additions */
1506  double vl = vp.x * vp.x + vp.y * vp.y + vp.z * vp.z;
1507  pl->pv.x += vp.x / vl;
1508  pl->pv.y += vp.y / vl;
1509  pl->pv.z += vp.z / vl;
1510  }
1511  }
1512 
1513  return (!FP_IS_ZERO(pl->pv.x) || !FP_IS_ZERO(pl->pv.y) || !FP_IS_ZERO(pl->pv.z));
1514 }
#define LW_FALSE
Definition: liblwgeom.h:94
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:34
static int get_3dcross_product(VECTOR3D *v1, VECTOR3D *v2, VECTOR3D *v)
Definition: measures3d.c:44
POINT3DZ pop
Definition: measures3d.h:57
VECTOR3D pv
Definition: measures3d.h:58
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 FP_IS_ZERO, get_3dcross_product(), get_3dvector_from_points(), getPoint3dz_p(), LW_FALSE, 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_line_tri(), lw_dist3d_point_poly(), lw_dist3d_point_tri(), lw_dist3d_poly_poly(), 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: