# Distance between polygons in 3d? (points of contact as a function of time)

## Main Question or Discussion Point

I was just wondering, is there a way to write a polygon as an equation in 3d? (Yes, a polygon, NOT a polyhedra)

It's intended to be a part of a collision detection program, so I need to be able to represent all points on a given polygon as an equation. Each polygon is being acted upon by forces as a function of time, so if I set the distance to 0 and solve for time, I get the time of contact.

How can I represent a polygon in such a way? I know the position of all vertices that make up this polygon (and the one it is to be compared to). It looks something like this-

Position.A + Velocity.A * Time = Position.B + Velocity.B * Time
so,
Time = (Position.A-Position.B) / (Velocity.A-Velocity.B)

Where position is a polygon and velocity is a vector. It's more complicated than this, but all I need is a way to plug a polygon into position.

It's intended to be a part of a collision detection program, so I need to be able to represent all points on a given polygon as an equation. Each polygon is being acted upon by forces as a function of time, so if I set the distance to 0 and solve for time, I get the time of contact.
Practically every 3D program since the advent of computers represents all objects as a collection of triangles. Is there some need to do it a different way?

Here's some nice links for collision detection. This site actually has quite a few nice programming articles for computer graphics:

http://www.gamedev.net/reference/list.asp?categoryid=45#199 [Broken]

Last edited by a moderator:
Oh, polygon implies triangle =/ (i'm not a math person- sorry).

Most of those systems use a corrective technique, and focus on efficiency. I'm focusing on precision and prediction, which is not very efficient.

Advanced techniques use a convex hull through minkowski addition, I don't understand this one bit, and don't really want to figure it out until I can do proper face to face comparisons. Sadly, the way I'm comparing is not the way others typically do it. In such a way, I need a little help making my own as opposed to learning how others do it.

Most of those articles focus on Narrow phase isolation efficiency and 2D corrective techniques (or on stuff that I'm not quite ready for).

Would my problem be easier to explain in terms of triangles?

I think part of my problem is that I cant just set the distance to 0 and solve. I need to find the point of contact between two triangles and then solve for time. For lines/points it's easy, but for triangles i'm at a loss.

So you're looking for a way to find the distance between the two nearest points on a triangle?

Well, there's a nifty equation for a triangle. Given endpoints p0, p1, and p2, the triangle is the set of all points p such that:

Angle(p0, p, p1) + Angle(p1, p, p2) + Angle(p2, p, p0) = 360º

(where Angle(A, B, C) is the angle between line segments AB and BC).

I'm not sure how useful that equation would be to find a minimum distance.

You can parametrize both points in 4 variables, so it might be possible (but difficult) to do a calculus minimum-value style analysis.

Err, the distance between two Triangles, not two points on a triangle.

The distance between two triangles will change as a function of time. So I intend to set the distance to 0 and solve for time to see when their trajectories will touch.