You can find the required math and a simple implementation right here:

http://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf[^]

12,063,645 members (56,844 online)

Email

Password

Sign in using

Hello

Im looking for a C/C++ code for a computing the minimum distance between a Point and Triangle in 3D. Please anyone can help me.

Thanks

Bojan

Im looking for a C/C++ code for a computing the minimum distance between a Point and Triangle in 3D. Please anyone can help me.

Thanks

Bojan

Comments

http://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada
+1 416-849-8900 x 100

First algorithm:

1) Find intersection of a line normal to a virtual side of the triangle.

2) Determine if intersection point is physically on the side. If not use the nearestend point.

3) Repeat for each of the sides.

Second algorithm:

If the point is inside the triangle when projected onto the plane of the triangle then the distance will be the distance from the point to the plane of the triangle, and if it's not then the distance will be the shortest distance between the point and any of the line segments of the triangle. But I can not find all those operations in code in one place, but maybe point projected onto plane, point in triangle, distance from point to plane, and distance from edge to point pretty easily separate.