[ODE] Distance between two objects

Martin C. Martin martin at metahuman.org
Mon Apr 19 15:23:39 MST 2004


Jeffrey Smith wrote:
> 
> The code snippet you pasted will tell him the distance between two geom's
> centers, not the shortest distance between the surfaces of two geoms. This
> can be a significantly more difficult problem.  
> 
> For the geometric primitives, analytic solutions can be derived with more 
> or less difficulty.  However, if you're using arbitrary trimeshes, the
> problem is very hard, and you may have to suffer approximations.

To be a little more precise: there's a simple, exact solution.  Just 
loop over all pairs of triangles (where 1st triangle of the pair is from 
the 1st trimesh, and 2nd triangle is from the 2nd trimesh), and find the 
distance between the triangles.  You want the pair with the shortest 
distance (which may not be unique).

However, if your trimeshes are of "reasonable" size, this will be really 
slow.  As always, the simple & inefficient solution may be the best in a 
lot of situations: if it's not the bottleneck, if your trimeshes are 
small, if this is for a Ph.D. thesis where it's cheaper to use more 
computers than more programmer time, etc.

This also assumes the trimeshes are hollow, i.e. that there's no charge 
in the area enclosed by the triangles.  However, it would probably be 
easy to handle this case, since you only need to check if one mesh is 
completely inside the other.

- Martin



More information about the ODE mailing list