[Math] How to simplify the calculations of reflecting a ray about an ellipse

geometry

enter image description here

enter image description here

enter image description here

enter image description here

I wrote the script that made these images several days ago, the segments each depict a ray of light, as the light hits the boundary of the ellipse, it is reflected by the ellipse according to the laws of reflection, and the reflected ray of light is again reflected by the ellipse, and the reflection of the reflection is again reflected by the ellipse…

The light keeps bouncing back and forth, over and over again, until the light has been reflected certain number of times.

Step by step on how I made these images.

First, you make an ellipse.

$\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1$

The above equation describes the points on the ellipse, it is also the boundary of the ellipse. (Assume the ellipse is horizontal).

Construct a right triangle from one semi-minor axis and one semi-major axis, let the acute angle adjacent to the semi-major axis be $\alpha$, then the relationship between a, b and $\alpha$ can be written as:

$b = a \cdot tan(\alpha)$

Rewrite the equation of the ellipse:

$\frac{x^2}{a^2} + \frac{y^2}{a^2 \cdot tan(\alpha)^2} = 1$

Pick a random point inside the ellipse, for all points inside by the ellipse, simply use this equation:

$\frac{x^2}{a^2} + \frac{y^2}{b^2} <= 1$

Then the random point is given as:

$(a \cdot cos(\alpha) \cdot m, b \cdot sin(\alpha) \cdot n)$

Where $\alpha$ is in range $[0, 2\pi]$, and m, n are in range $[0, 1]$.

Then pick a random angle $\beta$, to construct a line passes the chosen point at angle $\beta$ with the x-axis.

I use the slope-intercept form
of line equation ($y = k \cdot x + c$):

Let the chosen point be $(x_0, y_0)$, then the equation of the incident ray is:

$y = tan(\beta) \cdot x + y_0 – x_0 \cdot tan(\beta)$

But if $\beta$ is a multiple of $\frac{\pi} {2}$ things get complicated, because tan(0) = 0 and $tan(\frac{\pi} {2})$ is undefined.

So I use $y = y_0$ if the line is parallel to x-axis and $x = x_0$ if the line is perpendicular to x-axis.

Now to calculate the intersections between the incident ray and ellipse.

If:

$c^2 < a^2 \cdot k^2 + b^2$

Then there can be two intersections $(x_0, y_0)$ and $(x_1, y_1)$.


$$\begin{align}
n_1 &= a^2 \cdot k^2 + b^2 \\
n_2 &= 2 \cdot a^2 \cdot k \cdot c \\
n_3 &= a^2 \cdot (c^2 – b^2) \\
n_4 &= \sqrt{(n_2^2 – 4 \cdot n_1 \cdot n_3)} \\
x_0 &= \frac{(-n_2 + n_4)} {(2 \cdot n_1)} \\
x_1 &= \frac{(-n_2 – n_4)} {(2 \cdot n_1)} \\
y_0 &= k \cdot x_0 + c \\
y_1 &= k \cdot x_1 + c
\end{align}$$

For lines like $x = x_0$ and $y = y_0$ however:

First set:

If $abs(x_0) <= a$

$y_0 = \sqrt{b^2 – x_0^2 \cdot \frac{b^2} {a^2}}$

Intersections are $(x_0, +y_0)$ and $(x_0, -y_0)$.

Second set:

If $abs(y_0) <= b$

$x_0 = \sqrt{a^2 – y_0^2 \cdot \frac{a^2} {b^2}}$

Intersections are $(+x_0, y_0)$ and $(-x_0, y_0)$

Then choose the intersection to do further calculations, for $\beta$ in range $[0, \frac{\pi} {2}]$ and $[\frac{3 \pi} {2}, 2 \pi]$ I choose the right intersection, else I choose the left one.

Then I calculate the tangent of the ellipse at the intersection.

For a point $(x_0, y_0)$ on the ellipse given by a, b, the slope k of the line tangent to the ellipse at that point must satisfy:

$k = \frac{-x_0 \cdot b^2} {a^2 \cdot y_0}$

Then for almost all lines, the equation of the tangential line is:

$y = k \cdot x + \frac{b^2} {y_0}$

But if arctan(k) is a multiple of $\frac{\pi} {2}$ the above relationship breaks down and I instead fall back to constant form.

Then I calculate the normal (line perpendicular to that tangent passing through that intersection):

$y = \frac{-x} {k} + y_0 – \frac{-x_0} {k}$

Where $(x_0, y_0)$ is the intersection, and k is the slope of the normal.

But again the above relationship breaks down if the line is special. I won't show how I deal with exceptions here, I already have shown too many equations, you can see all the calculations in the code.

Then I calculate the signed angle formed by the incident ray and the normal:

Let $k_1$ be the slope of the incident ray, let $k_2$ be the slope of the normal:


$$\begin{align}
\alpha_1 &= atan(k_1) \\
\alpha_2 &= atan(k_2) \\
\alpha_\delta &= \alpha_2 – \alpha_1 \\
\alpha_\delta &= (\alpha_\delta + \pi) \bmod 2 \pi – \pi
\end{align}$$

Again, the above doesn't work if either of these lines are special, other calculations are required.

Then I calculate the reflected ray, simply by rotate the normal line about the intersection by $\alpha_\delta$ (assuming the previous calculations succeeded):

$$\begin{align}
\alpha_3 &= \alpha_2 + \alpha_\delta \\
y &= tan(\alpha_3) \cdot x + y_0 – tan(\alpha_3) \cdot x_0
\end{align}$$

Then I calculated the intersections between the reflected ray and the ellipse, there will be two intersections, this time the intersection needed is the other intersection from the current one.

Then all above calculations are repeated recursively, until a certain number of iteration is reached.

How to simplify all calculations involved, and calculate the reflected ray in as few steps as possible, including all the edge cases?


I want it that way: given the coordinate of a point and an angle, calculate the intersection of the ray with the ellipse, and then calculate the tangent of the ellipse at that intersection, then calculate the reflected ray, all of these in as few steps as possible, using one set of equations without exceptions. Preferably the number of equations involved should be less than or equal to six.

Best Answer

I think one can simplify the computations using vectors. Let's start with a ray emanating from point $A$ on the ellipse and being reflected at another point $B$ on the ellipse. The reflected ray is then $BA'$, where $A'$ is the reflection of point $A$ about the normal $BN$.

If $F$ and $G$ are the foci, finding point $N$ on segment $FG$ is not difficult, because $BN$ is the bisector of $\angle FBG$, which entails $FN:GN=FB:GB$. Hence (remembering that $FB+GB=2a$, the major axis of the ellipse): $$ N=\left(1-{FB\over2a}\right)F+{FB\over2a}G. $$ We can then find $M$, the projection of $A$ on line $BN$, setting $M=B+t(B-N)$ and using that the scalar product $(B-M)\cdot(A-M)$ vanishes. From there we can get $A'=2M-A$. One finds: $$ A'=2B-A+2t(B-N), \quad\text{where:}\quad t=-{(B-A)\cdot(B-N)\over(B-N)\cdot(B-N)}. $$ Once we have $A'$ we can find the other intersection $C$ of line $BA'$ with the ellipse, and repeat the whole process to compute next reflection.

enter image description here

Related Question