Thread: How to check for a collision between a triangle and a sphere

1. How to check for a collision between a triangle and a sphere

Hi list,

I want to detect when a sphere is overlapping a triangle at all. How can I do this?

I don't need velocity prediction or anything like that. Just all I want to know: Is a sphere defined by a position and a radius, overlapping at all a triangle, defined by 3 3d-vertexes.

2. Re: How to check for a collision between a triangle and a sphere

I guess you could juse see if the sphere intersects the triangles plane. If it intersects the plane then get the intersection point and test to see if it is contained inside of the triangle. There are probably better ways to do it, but this should at least get you started. Check Paul Bourke's Geometry page, http://www.swin.edu.au/astronomy/pbourke/geometry/, he probably has some stuff that will be useful. Also try searching on www.google.com, it is always a good place to look for information.

Nate Miller

3. Re: How to check for a collision between a triangle and a sphere

I don't think i'll work.. the problem is, the intersection isn't a point.. maybe you can test if any of the 3 triangle vertices is within the radius, and if they're not, find the closest point of the triangle to the center of the sphere, and check if this distance is withing the radius..

Y.

4. Re: How to check for a collision between a triangle and a sphere

Ysaneya - "find the closest point of the triangle to the center of the sphere" doesn't sound exactly like a trivial issue either. I would start by testing the sphere against the triangle's plane. That is a single number (the distance to the closest point in the plane) that can be easily found. If that value is within the radius then there may be an intersection, if not then there can not be an intersection. It appears (stress appears since I just woke up ) there are two cases left to check for, and fortunately they are easy. One test is to see if the closest point in the plane lies within the triangle. If it does then there must be an intersection. The other test is to see if any edge of the triangle intersects the sphere. I think that covers all the possibilities.

5. Re: How to check for a collision between a triangle and a sphere

Originally posted by DFrey:
Ysaneya - "find the closest point of the triangle to the center of the sphere" doesn't sound exactly like a trivial issue either. I would start by testing the sphere against the triangle's plane. That is a single number (the distance to the closest point in the plane) that can be easily found. If that value is within the radius then there may be an intersection, if not then there can not be an intersection. It appears (stress appears since I just woke up ) there are two cases left to check for, and fortunately they are easy. One test is to see if the closest point in the plane lies within the triangle. If it does then there must be an intersection. The other test is to see if any edge of the triangle intersects the sphere. I think that covers all the possibilities.

One case left, methinks... What if the triangle completely contains the sphere?
Like such:
Code :
```|\
| \
|  \
| o \
|____\```
Thats the harder case and I'm not exactly sure how to figure that one out. We know the sphere intersects the triangle's plane, all the triangle's points are outside the sphere's radius, and none of the edges intersect the sphere.

[This message has been edited by BwB (edited 12-30-2000).]

6. Re: How to check for a collision between a triangle and a sphere

That case is handled if the closest point in the plane of the triangle is in the triangle.

7. Re: How to check for a collision between a triangle and a sphere

You can intersect the sphere with the plane
of the triangle by projecting the center of
the sphere to the plane. If this point lies
within the triangle, you know they intersect.
Else you bring out the big (more expensive)
guns.

Calculate the radius of the circle that the
sphere intersecting the plane makes around
the projected point. For each triangle edge,
test whether the circle and the edge
intersect (using simple 2D math). If there
is at least one intersection, the sphere
collides with the triangle, else it doesn't.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•