# Ray-Ellipsoid Intersection question

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

## Recommended Posts

Hi, I've been [trying] to make a ray tracer, but am running into a problem. I've read, http://www.gamedev.net/community/forums/topic.asp?topic_id=308119 and implemented, but am having a problem. Basically, my ray-sphere intersection checker is receiving a lower value t for a sphere that *should* be farther away than another sphere. So I have two overlapping spheres, but wrong order. Here's my algorithm. Each sphere is only translated and scaled, so I manually set the values rather than invert the transformation matrix and multiply it. Translate and Scale: |Sx 0 0 Tx| |0 Sy 0 Ty| |0 0 Sz Tz| |0 0 0 1 | inverse of that is |1/Sx 0 0 -Tx/Sx| |0 1/Sy 0 -Ty/Sy| |0 0 1/Sz -Tz/Sz| |0 0 0 1 | So then I have my ray origin point and direction, and do the following newOrig.x = (1/Sx)*(ray.x - Tx) newOrig.y = (1/Sy)*(ray.y - Ty) newOrig.z = (1/Sz)*(ray.z - Tz) newD.x = (1/Sx)*rayD.x newD.y = (1/Sy)*rayD.y newD.z = (1/Sz)*rayD.z normalize(newDir) And then do the intersection with a unit sphere at origin with that ray. But like I said, this is returning smaller time values for the wrong sphere. Can anyone see a (likely obvious) problem I'm missing? Thanks for any help

##### Share on other sites
You should not be normalising the vector after scaling it, that is why you will be getting innacurate 'time' values

##### Share on other sites
Ah yes, that fixed the problem. Thanks very much! Oy, so much wasted time on that, can't believe I didn't realize what I had wrong.

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628724
• Total Posts
2984404

• 25
• 11
• 10
• 16
• 14