can't get ellipse to focus rays onto other focus

May 2010
4
1
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

Last edited:
May 2010
4
1
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:
Oct 2008
206
4
Hi Unclejoe.

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

(solveQuadratic)

is missing from your code. Will greatly appreciate if you can upload it too. Thanks
 
May 2010
4
1
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

  • Like
Reactions: noob mathematician
Oct 2008
206
4
Hi tks for the upload.

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
Mar 2010
2,340
821
Chicago
Hi tks for the upload.

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
(Largely in regards to the other thread linked to above)

Oh you're doing this for an internship? Haha, why didn't you mention that. I thought your physics friend just gave you the problem as a random challenge. Since it counts for work, I'd say that's different. I will PM you.

Sorry to mods if this response fits better in the other thread. It seemed to kind of fit here, at the time I posted, but in retrospect maybe not. Ah well, they're related enough that it shouldn't matter.
 
May 2010
4
1
I saw your entry and think that this could be helpful to my work
So, have you solved the ray, ellipse reflection problem using the code?