# can't get ellipse to focus rays onto other focus

#### UncleJoe

Greetings. I'm trying to do an optical simulation and wrote a ray, ellipsoid intersection function for Matlab/Octave. I fire a bundle of rays from 1 focus, and reflect them off the ellipse (see pictures).

In ellipse2.png, I choose the focus to be (0, -sqrt(1.2^2 - 1)) as it should be. I compute |hit - foci0| + |hit - foci1| and they're a constant 2.4 as expected, but the rays don't converge.

In ellipse1.png, I set the focus to (0, -.46). The rays now converge, but |hit - foci0| + |hit - foci1| no longer seem to be constant.

So I'm guessing the problem is with my intersection routine. Can anyone point out what's wrong?

(my code is a 2D version of the 3D case (YZ plane), so theta = 0 means straight up, instead of left)

1. First I find ray, ellipse intersection by expressing the ray as parametric equations (simple quadratic formula)

2. Find theta parameter associated with intersection: parametric form of ellipse is: y = b * sin(theta) z = c * cos(theta)
theta = atan2(hit.y, hit.z)

3. compute tangent vector dp_dtheta = [b * cos(theta), -c * sin(theta)]

4. rotate tangent vector -90 degrees to get surface normal at intersection

5. reflect the incident vector about the normal vector:
generate a rotation matrix with vector perpendicular to both incident & normal vector as axis. apply the rotation matrix to the incident vector to get the outgoing vector.

My main uncertainty is #3. I do this based on my knowledge of the PBRT raytracer. They compute the surface normal as CrossProduct(dp_du, dp_dv), where u & v, the surface parametization is in [0, 1].

update:

I've estimated the surface tangent by evaluating P(theta + 0.001) - P(theta). The estimated tangent vector matches the 1 computed above to 3 figures.
So now it's really a mystery. Is the reflection incorrect or am I using the wrong ellipse focus formula?

#### Attachments

• 73.1 KB Views: 13
• 76 KB Views: 10
• 1.4 KB Views: 1
Last edited:

#### UncleJoe

OK, I've found what's wrong - the theta = atan2(y, z) parametization is wrong. I plotted the tangent vectors and they weren't tangent to the ellipse, so I saw that the geometric angle the hit point makes with the z axis isn't the same as the theta I want.

It turns out. y / z = b sin(theta) / c cos(theta) = (b/c)tan(theta)

so theta = atan2((c / b) y, z)

Last edited:

#### noob mathematician

Hi Unclejoe.

Actually I am doing on a research on this too. I was trying to run your code but realised that the function

is missing from your code. Will greatly appreciate if you can upload it too. Thanks

#### UncleJoe

Here they are. I didn't expect anyone to want to run the program. I've included my 3D ellipsoid version as well. I only wrote the 2D ellipse version for debugging my problem. The wrong theta problem has been fixed for both.

testing.m (3D ellipsoid & hyperboloid)

test2d (2D ellipse)

What do you want to use it for?

I'm trying to find the feasibility of building a certain head mounted display described @ http://research.engineering.wustl.edu/~pless/omnivisFinal/nagahara.pdf

I only recently picked up Matlab from my job at 3M (image processing) and only wrote the program to debug my actual PBRT raytracer code. Much more convenient than C++.

#### Attachments

• 6.8 KB Views: 3
noob mathematician

#### noob mathematician

Actually I am currently doing my internship and was tasked to work on ray tracing which is not really my field of study. I am also very unsure of matlab manipulation.

I saw your entry and think that this could be helpful to my work. In particularly in solving the some questions which I posted previously.
HTML:
http://www.mathhelpforum.com/math-help/geometry/146420-finding-coordinates-when-light-hit-surface.html
So I was thinking maybe this code can assist me to achieve a better understanding on ray tracing in an ellipse

#### undefined

MHF Hall of Honor

Actually I am currently doing my internship and was tasked to work on ray tracing which is not really my field of study. I am also very unsure of matlab manipulation.

I saw your entry and think that this could be helpful to my work. In particularly in solving the some questions which I posted previously.
HTML:
http://www.mathhelpforum.com/math-help/geometry/146420-finding-coordinates-when-light-hit-surface.html
So I was thinking maybe this code can assist me to achieve a better understanding on ray tracing in an ellipse