Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

ellipsoid intersections

This topic is 2833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey people
so i was browsing the web to find a "tested" ray-ellipsoid intersection test, and i did, but i really didn't get the math behind it.
here it is:

bool IT_RayEllipsoid(D3DXVECTOR3 RayPos, D3DXVECTOR3 RayDir,
D3DXVECTOR3 m = RayPos - EllPos;
D3DXVec3Normalize(&RayDir, &RayDir);

float a = ((RayDir.x * RayDir.x) / (EllRadius.x * EllRadius.x))
+ ((RayDir.y * RayDir.y) / (EllRadius.y * EllRadius.y))
+ ((RayDir.z * RayDir.z) / (EllRadius.z * EllRadius.z));

float b = ((2.0f * m.x * RayDir.x) / (EllRadius.x * EllRadius.x))
+ ((2.0f * m.y * RayDir.y) / (EllRadius.y * EllRadius.y))
+ ((2.0f * m.z * RayDir.z) / (EllRadius.z * EllRadius.z));

float c = ((m.x * m.x) / (EllRadius.x * EllRadius.x))
+ ((m.y * m.y) / (EllRadius.y * EllRadius.y))
+ ((m.z * m.z) / (EllRadius.z * EllRadius.z))
- 1.0f;

float d = ((b * b) - (4.0f * a * c));

if (d < 0)
return false;
d = sqrt(d);

float hit = (-b + d) / (2.0f * a);
float hitsecond = (-b - d) / (2.0f * a);

float t;
if (hit < hitsecond)
t = hit;
t = hitsecond;

D3DXVECTOR3 Q = RayPos + t*RayDir;
*DistToEll = Q - RayPos;
return true;

i get the part about solving the quadratic equation, i just couldn't figure out how did a,b,c come in to place. What is the quadratic equation behind it??
last i checked, the ray-sphere equation is:
(p+td-C)(p+td-C) = r2
p = ray's position
d = normalized direction vector for the ray
C = sphere's center
r = sphere's radius
and then you just expand it, and solve for the two solutions(or no solution if it didn't intersect)

P.S: i tested it and it is working perfectly, the question is how???

Share this post

Link to post
Share on other sites
If you have a ray defined by SY9It.png, and the ellipse has an equation of ZRewG.png, then by substituting the 3 line equations into the ellipse equation you should get a quadratic equation in t that has the same coefficients as in the code sample you posted.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!