Hi there
I've been searching on the internetn for a while now, and I can't seem to find a function that determines wether a given sphere and ray intersect, and if so, what's the 'normal' at that point.
All help is welcome!
Ray-Sphere intersection
Page 1 of 12 Replies - 8538 Views - Last Post: 06 September 2009 - 03:01 AM
Replies To: Ray-Sphere intersection
#2
Re: Ray-Sphere intersection
Posted 06 September 2009 - 02:49 AM
This snippet from http://www.peroxide.dk looks like what you want.
double intersectRaySphere(D3DVECTOR rO, D3DVECTOR rV, D3DVECTOR sO, double sR) {
D3DVECTOR Q = sO-rO;
double c = lengthOfVector(Q);
double v = dot(Q,rV);
double d = sR*sR - (c*c - v*v);
// If there was no intersection, return -1
if (d < 0.0) return (-1.0f);
// Return the distance to the [first] intersecting point
return (v - sqrt(d));
}
This post has been edited by Lillefix: 06 September 2009 - 02:55 AM
#3
Re: Ray-Sphere intersection
Posted 06 September 2009 - 03:01 AM
Thanks!
This post has been edited by Pontus: 06 September 2009 - 06:06 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|