#### Archived

This topic is now archived and is closed to further replies.

# The distance between 2 triangles?

This topic is 5371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I need a algorithm to calculate the distance between 2 triangles in 3D space! thx!

##### Share on other sites
the distance between which parts of the triangles? each infinetesimally small part of each triangle is a different distance away from each infinetesimally small part of the other triangle.

if you mean just the center, it''s a simple distance formula:

distance = sqrt( (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2 );

if you mean the how far apart the triangles are at their closest point, i guess you''d have to do distance from a point to a plane equation which involves some linear algebra (look up "3d math tutorial" in google for a brief introduction and some equations).

dunno if that helps. can you be more specific?

-me

##### Share on other sites
I wrote an algorithm that does what you want -- it''s used in my triangle-triangle collision program. The function is triangle::Distance() in the file DataTypes.h. You can read a little about it at the top of Main.cpp.

The function is complicated, but it works -- I haven''t noticed any bugs yet.

~CGameProgrammer( );

-- Post screenshots of your projects. 100+ posts already in the archives.

##### Share on other sites
this may be of use:

http://astronomy.swin.edu.au/~pbourke/geometry/linefacet/

if your ultimate goal is to determine if two triangles intersect.

##### Share on other sites
my goal is to calculate the distance between their closet points,
thx

##### Share on other sites
Yes, that''s what mine does -- return the minimum distance between the two triangles. It doesn''t return the points themselves but it returns the distance.

~CGameProgrammer( );

-- Post screenshots of your projects. 100+ posts already in the archives.

##### Share on other sites
thank you, CGP
but what "Direction" means in
UINT Distance ( Type* Distance, plane* Plane, triangle Other, vector Direction )
?
i just want to know how to calculate the minimum distance between *stationary* triangles.

##### Share on other sites
quote:
Original post by gotton
thank you, CGP
but what "Direction" means in
UINT Distance ( Type* Distance, plane* Plane, triangle Other, vector Direction )
?
i just want to know how to calculate the minimum distance between *stationary* triangles.

Oh yeah, I forgot. Sorry. Then my code isn''t what you want.

~CGameProgrammer( );

-- Post screenshots of your projects. 100+ posts already in the archives.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 9
• 13
• 78
• 11
• 10
• ### Forum Statistics

• Total Topics
632968
• Total Posts
3009589
• ### Who's Online (See full list)

There are no registered users currently online

×