Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ray->Sphere intersection



Here's one from "Mathematics for 3D Game programming and Computer Graphics". If it's the most efficient one I can't comment on.

Sphere with radius r at origin (0, 0, 0):

X^2 + Y^2 + Z^2 = r^2

Ray defined as:

P(t) = Q + tV

Q = ray origin
V = ray direction

Substituting the components of the ray for x, y and z gives:

(Qx + tVx^2) + (Qy + tVy^2) + (Qz + tVz^2) = r^2

Expanding the squares and collection on t gives the quadratic equation:

(Vx^2 + Vy^2 + Vz^2)t^2 + 2(QxVx + QyVy + QzVz)t + Qx^2 + Qy^2 + Qz^2 - r^2

Coefficients a, b and c in

at^2 + bt + c = 0 can be expressed in terms of V and Q as

a = V^2
b = 2(Q dot V)
c = Q^2 - r^2

Discriminant D = b^2 - 4ac tells if the ray intersects the sphere.

if D < 0, no intersection.
D = 0, the ray is tangent to the sphere.
D > 0, ray intersects at two points.

The point closer to origin Q, which corresponds to the smaller value of t is given by

t = ( -b - sqrt(D) ) / 2a


Ken


On Monday, December 30, 2002, at 06:08 PM, Brian Greenstone wrote:

Does anyone have some good, efficient code for doing Ray-Sphere intersection
tests?

Thanks-

-Brian

_________________________________________________________
Brian Greenstone
President & CEO email@hidden
Pangea Software, Inc. http://www.pangeasoft.net
12405 John Simpson Court voice/fax: (512)266-9991
Austin, TX 78732
_________________________________________________________
_______________________________________________
mac-opengl mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/mac-opengl
Do not post admin requests to the list. They will be ignored.
_______________________________________________
mac-opengl mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/mac-opengl
Do not post admin requests to the list. They will be ignored.

References: 
 >Ray->Sphere intersection (From: Brian Greenstone <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.