Jump to content
  • Advertisement
Sign in to follow this  
phb5000

Sphere-Triangle Collision

This topic is 4483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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,

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Solution 1 is the famous stencil buffer shadow technique :-)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!