I'm not really sure where to start looking for info about this question, so I'm asking here. Hopefully it's not too general. I've written a particle library in C++ and am trying to add the ability to constrain particles to the surface of a mesh. Not a rigid constraint though -- I want particles to be able to slide over the surface when affected by forces.
So, imagine I have an arbitrary concave mesh with n triangular faces. I then have a 3d point (particle) located on one of the faces. A apply a directional force to that particle to get it moving, but I want it to move along the topology of the surface, not simply move linearly through space. It should move smoothly over the surface and always be touching a triangle of the mesh.
I've thought about moving the particle linearly at first, and then snapping it to the closest point on the surface, but that would run into a lot of problems, like the particle might snap to other non-contiguous parts of the mesh simply because they happen to be a shorter distance to the particle after it's been moved by the force.
Then I thought about checking its barycentric coordinates and using them to determine which adjacent triangle it should move onto, if it leaves the bounds of its current triangle...but that seems like a hugely inefficient solution riddled with other problems (like if the force moves the particle past the bounds of all adjacent triangles as well).
Then I thought about using UVW coordinates to figure out where the particle would move to, but that wouldn't work either.
Any ideas?
Here's an image to help illustrate the problem: