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.
Gwendolyn Fischer (2021). Distance between a point and a triangle in 3D (https://www.mathworks.com/matlabcentral/fileexchange/22857-distance-between-a-point-and-a-triangle-in-3d), MATLAB Central File Exchange. Retrieved .
Thank you for sharing the function. I have a question about it.
To analyze the deformation of a surface, for example, I would like to monitor this surface (facade of a building) every 2 hours. So every 2 hours I get a new point cloud which I have to compare with a reference area.my meshed surface and each point cloud consists of several points (about 400000 points), which have only x-, y- and z-coordinates. How can I use this function to represent the distance between the surface and the point cloud as a colored figure?
Thank you for your help and your suggestion.
may i know how to run the code?
Great function! I've found that using a different version of the dot product i.e. sum(E0.*E0) vs dot(E0,E0) speeds up execution considerably in Matlab 2016b.
Very nice, and faster than my implementation. However, there's an error somewhere in there. Try plugging the following triangle and point in:
But tridist should be the same as the norm from the initial point to the closest point (output from the function as PP0). Plotting it, it looks like PP0 is getting to the right spot, so there must be an issue with that particular path through the code. Notice that if you truncate the values I gave above, the correct answer is reached (i.e. if you only use 4 places past the decimal).
good job,thank you, i learn a lot.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!