Sphere-Triangle Collision

Started by
17 comments, last by Kwizatz 18 years, 1 month ago
I dont know how long I've looking for a simple solution to a sphere-triangle collision detection, but I cant seem to find any concrete solutions to it! My situation is as follows: + I have a sphere (representing a first person shooter camera) + I have a mesh (representing a level) Collision Detection: + Check distance from the plane of nearby faces to the sphere's position + If <= Radius then make sure the sphere is within the triangle. <-- problem The data I have to use is the position of the sphere, the normal of the face plane, and the three vertices of the face itself. How can I know check to see that If the sphere where to be touching the face plane Exactly (which will mostly likely never happen) is the point in the area of the triangle? Should I go for a different approach? Should I generate a triangular prism representing the face + normal data * distance to sphere. Then check if they overlap? Any suggestions, links, or any other resources are appreciated! Thank you,
Advertisement
How about:

Compute the minimum distance from the triangle to the center of the sphere. Mathematically, this could be a minimization double integral in barycentric coordinates. If the distance is less than r then you have a collision.
Project the position (center) of the sphere along the surface normal. If the value is greater than the spheres radius, the sphere doesn't penetrate the triangle so break. Otherwise, find the image of the sphere projected on the plane and test whether that point is inside the triangle.

--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet

Quote:test whether that point is inside the triangle.


Thats what I dont know how to do...
Once you have a point in the plane of the triangle, it is easy to test whether it is inside the triangle </reassurance>. [wink] See solution 3 of this webpage.

--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet

Solution 1 is the famous stencil buffer shadow technique :-)
Quote:Original post by WhardieJones
Compute the minimum distance from the triangle to the center of the sphere. Mathematically, this could be a minimization double integral in barycentric coordinates. If the distance is less than r then you have a collision.
If you just need a discrete test, I'd go for this method. The info returned by the closest point test can be used to resolve the intersection, which also gives you fairly natural sliding collision response. This will only work for objects that move relatively slowly, though.
Hey!! I have posted the correct method here (your thread on the DirectX forum)...

Sorry man, Ive wrote the wrong code but now its right...the problem was with the s and t computation...just confused with the distance between a point and a line computation :P...read that and if you have any questions its just ask ;)

.
Quote:Mathematically, this could be a minimization double integral in barycentric coordinates. If the distance is less than r then you have a collision.


Would you mind elaborating/posting a source on this?
phb5000, please read this excellent article by David Eberly. You can find the source code as well at his site.

Quote:Original post by jjd
Project the position (center) of the sphere along the surface normal. If the value is greater than the spheres radius, the sphere doesn't penetrate the triangle so break. Otherwise, find the image of the sphere projected on the plane and test whether that point is inside the triangle.

Unfortunately, this is not enough. Even if the sphere center's projection onto the plane is outside the triangle, the sphere can still collide with the triangle.

WhardieJones, didn't you mean to minimize the distance function between the sphere's center and the triangle? In any case, this is not a "simple" minimization problem because the barycentric coordinates are subject to the following constraints:
0 <= s,t
1 >= s+t

This topic is closed to new replies.

Advertisement