Created
September 26, 2011 08:20
-
-
Save jcayzac/1241840 to your computer and use it in GitHub Desktop.
Charles Bloom algorithm for sphere-cone intersection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
V = sphere.center - cone.apex_location | |
a = V * cone.direction_normal | |
b = a * cone.tan | |
c = sqrt( V*V - a*a ) | |
d = c - b | |
e = d * cone.cos | |
now if ( e >= sphere.radius ) , cull the sphere | |
else if ( e <=-sphere.radius ) , totally include the sphere | |
else the sphere is partially included. | |
What's going on in this cone-sphere test? Basically, I'm trying to find 'e' which is the shortest distance from the center of the sphere to the surface of the cone. You can draw some pictures and see what's going on. 'a' is how far along the ray of the cone the sphere's center is. 'b' is the radius of the cone at 'a'. 'c' is the distance from the center of the sphere to the axis of the cone, and 'd' is the distance from the center of the sphere to the surface of the cone, along a line perpendicular to the axis of the cone (which is not the closest distance). | |
Note that once you compute 'a' you could tell that the sphere intersects the cone just by testing | |
Square( a ) <= V*V * Square( cone.cos ) | |
This is very fast and nice, but it can't tell us if the sphere was partially included or totally included, so it's no good for heirarchy. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment