PDA

View Full Version : Point/Box in sphere-check?



B_old
02-13-2003, 11:26 AM
Hello.
I want to check wether a box is intersecting a sphere with at least one corner.
I know this is not OGL related but if you have some code please post it. I just can't get it right, I' tired and stuff. Thanks for the help...

shinpaughp
02-13-2003, 11:41 AM
Not sure if this is what you are looking for, but if you know the center point of the sphere and the radius of the sphere, find the line between center of sphere and corner of box. Find the length of line. If line length is less than radius then box corner point is within sphere.

jebus
02-14-2003, 08:26 AM
if ((box_corner - circle_center) < circle_radius)
{
// intersecting
}
else if ((box_corner - circle_center) > circle_radius)
{
// not intersecting
}
else
{
// touching each other
}


jebus

[This message has been edited by jebus (edited 02-14-2003).]

B_old
02-15-2003, 03:10 AM
OK, thanks I got something working now.