Jump to content
  • Advertisement
Sign in to follow this  
VISQI

Ray-Ellipsoid Intersection test

This topic is 2351 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

ok people. I have been searching about this thing for a while and i found many good tests but most of them i didn't understand.
From what i heard, a Ray-Ellipsoid Intersection Test in exactly like a Ray-Sphere Intersection Test but with converting the ray to ellipsoid space, meaning that you multiply it by a 3x3 matrix that represents the radii of the 3 axises of the ellipsoid.
I just want to know if there is something i missed
here is the quick code


float IT_RayEllipsoid(D3DXVECTOR3 RayOrigin, D3DXVECTOR3 RayVec,
D3DXVECTOR3 EllRadius, D3DXVECTOR3 EllAxis[])
{
D3DXMATRIX ToEllipsoid;
D3DXVECTOR3 xAxis = EllAxis[0] * EllRadius.x;
D3DXVECTOR3 yAxis = EllAxis[1] * EllRadius.y;
D3DXVECTOR3 zAxis = EllAxis[2] * EllRadius.z;
ToEllipsoid(0,0) = xAxis.x;
ToEllipsoid(1,0) = xAxis.y;
ToEllipsoid(2,0) = xAxis.z;

ToEllipsoid(0,1) = yAxis.x;
ToEllipsoid(1,1) = yAxis.y;
ToEllipsoid(2,1) = yAxis.z;

ToEllipsoid(0,2) = zAxis.x;
ToEllipsoid(1,2) = zAxis.y;
ToEllipsoid(2,2) = zAxis.z;

D3DXVec3TransformCoord(&RayOrigin, &RayOrigin, &ToEllipsoid);
D3DXVec3TransformNormal(&RayVec, &RayVec, &ToEllipsoid);

//Since it is in ellipsoid space, the center = 1.0f and the radius is 0,0,0
float Radius = 1.0f;
D3DXVECTOR3 Center = ZEROVEC;
D3DXVECTOR3 m = RayOrigin - Center;
float b = D3DXVec3Dot(&m, &RayVec);
float c = D3DXVec3Dot(&m, &m) - Radius * Radius;
// Exit if r’s origin outside s (c > 0) and r pointing away from s (b > 0)
if (c > 0.0f && b > 0.0f) return -1.0f;
float discr = b*b - c;
// A negative discriminant corresponds to ray missing sphere
if (discr < 0.0f) return -1.0f;
// Ray now found to intersect sphere, compute smallest t value of intersection
float t = -b - sqrt(discr);
// If t is negative, ray started inside sphere so clamp t to zero
if (t < 0.0f) t = 0.0f;
return RayOrigin + t*RayVec;
}



The code is originally a Ray-Sphere intersection test taken from "Real-Time Collisions" by Christer Erikson. I just added the matrix thing to change it to Ellipsoid space.

Share this post


Link to post
Share on other sites
Advertisement
I'm not familiar with D3DX calls, but conceptually this is quite simple: Find coordinates in which your ellipsoid looks like a unit sphere, convert the ray to those coordinates, compute the intersection in those coordinates and convert back to the original coordinates. [EDIT: Solving for t and using this value to compute a point in the ray, as you are doing, is perfectly fine too.]

If I am not mistaken, you need to convert the ray to "sphere" coordinates by multiplying by the inverse of the matrix whose columns are the axes of the ellipsoid.

Share this post


Link to post
Share on other sites

I'm not familiar with D3DX calls, but conceptually this is quite simple: Find coordinates in which your ellipsoid looks like a unit sphere, convert the ray to those coordinates, compute the intersection in those coordinates and convert back to the original coordinates. [EDIT: Solving for t and using this value to compute a point in the ray, as you are doing, is perfectly fine too.]

If I am not mistaken, you need to convert the ray to "sphere" coordinates by multiplying by the inverse of the matrix whose columns are the axes of the ellipsoid.


great. I just need to multiply the ray's vector and origin by the INVERSE of the matrix not the actual one. Thanks. I thought it was much more complicated :)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!