What am I doing wrong with trying to find the intersection equation between an offset Ellipse and a Ray?

84 Views Asked by At

In relation to another, recent post, I am having trouble finding the intersection equation between an offset Ellipse and a Ray (line restricted by a point). Due to the equations being necessary for a computational application, the parameters cannot be replaced by actual values, this is done in the computations.

The Ray is defined as follows: $$ \begin{cases} x = o_1 + m \cdot v_1, \\ y = o_2 + m \cdot v_2, \end{cases} $$ $O = (o_1, o_2)$ is the origin, or restriction point of the ray, and $$ V = \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} $$ The Ellipse is defined as follows: $$ \frac{(x-h)^2}{a^2} + \frac{(y - k)^2}{b^2} = 1, $$ where $a$ and $b$ are the eccentricity in $x$ and $y$, $h$ and $k$ the offset in $x$ and $y$ from the origin.
To simplify the algebra, I converted the parametric equation of the ray to a cartesian equation: $$ y = \frac{v_2}{v_1} x + o_2 - \frac{v_2}{v_1} o_1, $$ and then set $$ c = \frac{v_2}{v_1}, d = o_2 - c\cdot o_1. $$ The final result is this: $$ x = \frac{b^2h-a^2c(d-k) \pm ab\sqrt{b^2+a^2c^2 -(ch + d - k)^2}}{b^2+a^2c^2},\ y = cx+d. $$ This equation should give the intersection between a line $y = cx + d$ and the earlier defined ellipse. however, when setting up this equation in Geogebra, I do not get the expected results. I have checked and redone the algebra multiple times, and I cannot find the error or bad approach angle. The geogebra setup is here: https://www.geogebra.org/calculator/zpvnjtkj

enter image description here

EDIT:
the equations are for use in code, where the variables will be replaced each time the equation is used and would be "known". the code is for a 2D light propagation, with reflections from elliptical and linear mirrors. Due to accumulating errors, the equation has to be as good as possible and testing using geogebra to check if the calculated intersections are on the ellipse circumference is not working. I will redo the algebra by solving for $m$ or $t$, to use better notation.

EDIT 2:
After constructing the ellipse, Ray and intersection equation solving for the factor of $V$, I found something interesting:
If a or $b$ are bigger or smaller than 1, the intersection is off. However, if $a$ and $b$ are equal to 1: the intersection is correct.
https://www.desmos.com/calculator/7fhdwyzwm8


Edit 3:
Below is the desmos graph when a and b are equal to 1 or -1:

graph when <span class=$a$ and $b$ are equal to 1 or -1" />


Below is the same graph when b is not equal to 1 or minus 1:

graph when a  or b are not equal to 1 or -1


It might be slightly hard to see, but the blue point on the green line is the point the intersection equation finds. in the first image, the point is on the ellipse periphery. $a$ and $b$ are both equal to 1. in the second image, the point is not on the ellipse periphery. $b$ in the second image is equal to $-1.76$

2

There are 2 best solutions below

2
On

The ray is defined by the vector parametric equation

$ R(t) = O + t V $ where $ t \gt 0 $

The ellipse is defined by

$$ (r - r_0)^T Q (r - r_0) = 1 $$

where $ r = [x, y]^T $ , $ r_0 = [h, k]^T $ and

$Q = \begin{bmatrix} \dfrac{1}{a^2} && 0 \\ 0 && \dfrac{1}{b^2} \end{bmatrix}$

Substituting the equation of the ray into the equation of the ellipse gives

$ (O + t V - r_0)^T Q (O + t V - r_0 ) = 1 $

Expanding this equation gives

$ t^2 \ V^T Q V + 2 t \ V^T Q (O - r_0) + (O - r_0)^T (O - r_0) - 1 = 0 $

which is of the form

$ a t^2 + b t + c = 0 $

with

$ a = V^T Q V $

$ b = 2 V^T Q (O - r_0)$

$ c =(O - r_0)^T (O - r_0) - 1 $

The solution of this quadratic equation in $t$ is via the quadratic formula which gives us,

$ t_{1,2} = \dfrac{ - b \pm \sqrt{b^2 - 4 a c } } { 2 a } $

Solutions will exist only if $b^2 - 4 a c \ge 0 $. Acceptable values of $t$ are the positive ones. There could be one, two , or no solutions.

Once we've determined the allowable values of $t$, we substitute that into the equation of the ray to get the point $r = [x, y]^T $.

2
On

The discriminant you obtained may be rewritten to bring in slope $m$:

$$ \text{Let} ~~Q= {b^2+a^2c^2 -(ch + d - k)^2};\tag 1 $$

$$(x_1,x_2)=\frac{b^2h-a^2c(d-k) \pm ab\sqrt{Q}}{b^2+a^2c^2},( y_1,y_2) = (cx_{1}+d,c x_{2}+d); $$

enter image description here

If $Q=0$ there are 2 tangents.

If $Q>0$ there are 2 real intersections between the tangents.

If $Q<0$ there are 2 complex conjugate intersections "outside" them, cannot be graphically shown.