Skip to main content
1 of 5
Julian Mann
  • 123
  • 1
  • 1
  • 6

algorithm to find the coordinates of a particle in a swept triangle.

Hi - I posted a question at my site - no one answered it sufficiently, despite the bounty, so I'll ask it here.

-- first the question I asked: I want to write a field in maya that applies a force in the space between 2 pieces of geometry. They can be topologically identical triangulated meshes. So the problem comes down to testing if a particle is in the volume swept out between a pair of triangles, and if so, finding its coordinates. If the particle is in the sweep, there will be a line passing through it and meeting both triangles at the same barycentric coordinates on each triangle. It would be nice to know the barycentric coordinates because then the force can be UV textured. Also I would need to know the parameter along the line so the force can be attenuated. I managed a bad hack once that worked if the triangles were nearly parallel and similar size, but it fell apart fairly fast. Intuitively it seems doable though.

-- then, the only answer, which while helpful, was beyond my mathematical abilities to turn into computer code:

If 't' is the parameter along the line, then section 6 of this has a cubic in 't' which you can solve to find the "time" at which the swept triangle and particle are coplanar (assuming the particle velocity is zero, and disregarding any solutions outside 0-1). Then lerp the triangle vertices using 't', and find the barycentric coordinates of the particle with respect to that interpolated triangle in the usual way. It breaks down if the two triangles are coplanar though.

-- so I need the function with this prototype:

bool pointInSweptTriangle( triangle t0, triangle t1, point p, vector &bary, float &t);

Many Thanks!

Julian Mann
  • 123
  • 1
  • 1
  • 6