PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ define_plane()

int define_plane ( const POINTARRAY pa,
PLANE3D pl 
)

Definition at line 1491 of file measures3d.c.

1492{
1493 const uint32_t POL_BREAKS = 3;
1494
1495 assert(pa);
1496 assert(pa->npoints > 3);
1497 if (!pa)
1498 return LW_FALSE;
1499
1500 uint32_t unique_points = pa->npoints - 1;
1501 uint32_t i;
1502
1503 if (pa->npoints < 3)
1504 return LW_FALSE;
1505
1506 /* Calculate the average point */
1507 pl->pop.x = 0.0;
1508 pl->pop.y = 0.0;
1509 pl->pop.z = 0.0;
1510 for (i = 0; i < unique_points; i++)
1511 {
1512 POINT3DZ p;
1513 getPoint3dz_p(pa, i, &p);
1514 pl->pop.x += p.x;
1515 pl->pop.y += p.y;
1516 pl->pop.z += p.z;
1517 }
1518
1519 pl->pop.x /= unique_points;
1520 pl->pop.y /= unique_points;
1521 pl->pop.z /= unique_points;
1522
1523 pl->pv.x = 0.0;
1524 pl->pv.y = 0.0;
1525 pl->pv.z = 0.0;
1526 for (i = 0; i < POL_BREAKS; i++)
1527 {
1528 POINT3DZ point1, point2;
1529 VECTOR3D v1, v2, vp;
1530 uint32_t n1, n2;
1531 n1 = i * unique_points / POL_BREAKS;
1532 n2 = n1 + unique_points / POL_BREAKS; /* May overflow back to the first / last point */
1533
1534 if (n1 == n2)
1535 continue;
1536
1537 getPoint3dz_p(pa, n1, &point1);
1538 if (!get_3dvector_from_points(&pl->pop, &point1, &v1))
1539 continue;
1540
1541 getPoint3dz_p(pa, n2, &point2);
1542 if (!get_3dvector_from_points(&pl->pop, &point2, &v2))
1543 continue;
1544
1545 if (get_3dcross_product(&v1, &v2, &vp))
1546 {
1547 /* If the cross product isn't zero these 3 points aren't collinear
1548 * We divide by its lengthsq to normalize the additions */
1549 double vl = vp.x * vp.x + vp.y * vp.y + vp.z * vp.z;
1550 pl->pv.x += vp.x / vl;
1551 pl->pv.y += vp.y / vl;
1552 pl->pv.z += vp.z / vl;
1553 }
1554 }
1555
1556 return (!FP_IS_ZERO(pl->pv.x) || !FP_IS_ZERO(pl->pv.y) || !FP_IS_ZERO(pl->pv.z));
1557}
#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_3dcross_product(const VECTOR3D *v1, const VECTOR3D *v2, VECTOR3D *v)
Definition measures3d.c:44
static int get_3dvector_from_points(const POINT3DZ *p1, const POINT3DZ *p2, VECTOR3D *v)
Definition measures3d.c:34
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: