Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

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

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2000
    Location
    London
    Posts
    28

    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. #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. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Posts
    748

    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. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    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. #5
    Junior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Ocoee, Florida, USA
    Posts
    155

    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. #6
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    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. #7
    Guest

    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
  •