Created
September 26, 2011 08:31
-
-
Save jcayzac/1241858 to your computer and use it in GitHub Desktop.
My 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 = dotProduct(V, cone.direction_normal) | |
p = a * cone_sin | |
q = cone_cos * cone_cos * dotProduct(V, V) - a*a | |
r = q - sphere_radius * sphere_radius | |
if ((p < sphere_radius) || (q > 0)) { | |
if (r < 2 * sphere_radius * p) | |
return -1; // Sphere and cone enveloppes intersect | |
else if (q < 0) | |
return 1; // Sphere is totally included in cone | |
else | |
return 0; // Shere and cone don't intersect at all | |
} | |
else { | |
if ( -r < 2 * sphere_radius * p) | |
return -1; // Shpere and cone enveloppes intersect | |
else if (q < 0) | |
return 1; // Sphere is totally included in cone | |
else | |
return 0; // Sphere and cone don't intersect at all | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment