• Advertisement

Archived

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

The distance between 2 triangles?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement