The distance between 2 triangles?

Started by
6 comments, last by gotton 20 years, 2 months ago
I need a algorithm to calculate the distance between 2 triangles in 3D space! thx!
Advertisement
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
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.
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
this may be of use:

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

if your ultimate goal is to determine if two triangles intersect.
my goal is to calculate the distance between their closet points,
thx
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.
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
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.
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.
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement