# Ray-Ellipsoid Intersection test

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

## 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 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.

##### 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

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013753
×