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

◆ define_plane()

int define_plane ( POINTARRAY pa,
PLANE3D pl 
)

Definition at line 1451 of file measures3d.c.

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