Click here to Skip to main content
11,705,052 members (50,707 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++/CLI C VC10.0

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.

Posted 11-Jul-10 7:53am
Sandeep Mewara at 11-Jul-10 14:01pm
What have you tried so far? Any effort made till now?
Member 4644164 at 12-Jul-10 7:04am
Yea I have some algorithm but still not implemented in a C/C++ code.

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can find the required math and a simple implementation right here:[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

this might be useful for you:[^]
CHill60 at 7-Aug-13 10:00am
FYI Answering questions that are 3 years old and already resolved, with a link that just links back to this question will attracct downvotes

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 609
1 OriginalGriff 439
2 Andy Lanng 215
3 CPallini 202
4 F-ES Sitecore 160
0 OriginalGriff 8,958
1 Sergey Alexandrovich Kryukov 8,276
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 7 Aug 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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