View Full Version : Sphere-sphere collision detection

Billy Lee

01-08-2003, 09:24 AM

I am having so much trouble working out how to do sphere-sphere collision detection. I've done lots of research but they all seem to concentrate on the situation of a sphere passing through another sphere (thus seemingly no collision) rather than detecting if one sphere touches another one (which I need as a starting point and can build upon myself). They say it's easy but I can't figure it out (I don't know much about dot and cross product). Could someone give me a brief description on how to detect sphere-sphere collisions?

Halcyon

01-08-2003, 09:54 AM

I've never implemented one or anything, but i have a really basic understanding of it. In a sphere, the radius is constant right? So say you have two spheres floating around. If the distance between the two spheres is less than the sum of radius one and radius two, then you ahve collision.

For example say you have a bullet heading towards a person. The person's sphere has a radius of 4 units and the bullet has a radius of 2 units (yeah it's a big bullet). So it looks like this

2 2 4 units 4 units

|----|----| |--------|--------|

bullet person

If the distance from the center of the the bullet sphere to the center of the person sphere was less than or equal to 6, then we have a collision. There are 2 2's and 4's because that is the length of the radius and i'm showing the diameter. I hope this makes sense. If you don't get something about it, just say so and i'll elaborate or clear it up.

- Halcyon

Edit: Sorry the picture was kinda misaligned.

[This message has been edited by Halcyon (edited 01-08-2003).]

Morglum

01-08-2003, 10:03 AM

Yeah, that's it. Here are the formulas :

Assume the spheres are named A and B.

Denote by rA and rB their radii, and by (xA, yA, zA) and (xB, yB, zB) the coords of their centers.

Then :

The spheres intersect each other if and only if

(xA-xB)²+(yA-yB)²+(zA-zB)² < (rA+rB)²

The spheres are tangent to each other if and only if

(xA-xB)²+(yA-yB)²+(zA-zB)² = (rA+rB)²

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.