pyFM.spectral.projection_utils.pointTriangleDistance¶
- pyFM.spectral.projection_utils.pointTriangleDistance(TRI, P, return_bary=False)¶
Computes distance between a point and a triangle in a p-dimensional space
Note
Based on the implementation in (modified to return barycentric coordinates of the projection): https://gist.github.com/joshuashaffer/99d58e4ccbd37ca5d96e
- DESCRIPTION
Calculate the distance of a given point P from a triangle TRI. Point P is a row vector of the form 1x3. The triangle is a matrix formed by three rows of points TRI = [P1;P2;P3] each of size 1x3. dist = pointTriangleDistance(TRI,P) returns the distance of the point P to the triangle TRI. [dist,PP0] = pointTriangleDistance(TRI,P) additionally returns the closest point PP0 to P on the triangle TRI.
The algorithm is based on “David Eberly, ‘Distance Between Point and Triangle in 3D’, Geometric Tools, LLC, (1999)” http:\www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf
- Parameters:
TRI ((3, p) np.ndarray) – A p-dimensional triangle.
P ((p,) np.ndarray) – Coordinates of the point.
return_bary (bool, optional) – Whether to return barycentric coordinates inside the triangle.
- Returns:
dist (float) – Distance from the point to the triangle.
projection ((p,) np.ndarray) – Coordinates of the projected point.
bary_coords ((3,) np.ndarray) – Barycentric coordinates of the projection within the triangle. Returned ONLY if return_bary is True.