PDA

View Full Version : opengl line sphere intersection



09-30-2001, 07:13 AM
in my extremely exciting opengl project i need a function that works like this, to return an intersection for a sphere and line segment.

defined values:
sphere is the point where the sphere sits. x,y,z
line_start is the point where the line originates
line_end is the ending point of that line
readius is the radius of the sphere


bool Intersection(float sphere[3], float line_start[3], float line_end[3], float radius)
{
if intersection return true;
else return false;
}

Im not worried about point of intersection, just if an intersection does exist.

Leyder Dylan
09-30-2001, 08:53 AM
http://www.magic-software.com/Intersection3D.html

10-01-2001, 05:15 AM
ok i looked at that page, whatever usefull there has one half million dependancies, not something i want, just a simple function to calculate intersection or not.. as i said im not caring about point of intersection.. just if intersection exists between a line and a sphere, surely someone can help! thanks.

Gavin
10-01-2001, 08:07 AM
Work out the length of the normal that you get from the centre of your sphere to the line. If the length of this normal is less than your sphere radius then you get an intersection. If you draw it on a bit of paper you will see what I mean.

gav