In a recent post I've investigated the ellipse tangent to the $x$ and $y$ axes as well as a third given line.
In this problem, you're given a triangle with known vertices, and your task is to find the inscribed ellipse that is tangent to all three sides of the triangle. Since there is an infinite number of these ellipses, we have to narrow it down. So assume that you are also given the direction of the major axis as the angle it makes with the $+x$-axis direction, and also you're given the ratio of the major to minor axes.
This is the task: Finding the equation of the ellipse under the given conditions.
I appreciate your input, comments, hints, and solutions.
My attempt:
Assume the vertices of the triangle are the three points $\mathbf{p_1, p_2, p_3}$.
The equation of the ellipse to be found is
$ (\mathbf{r - C})^T Q (\mathbf{r - C}) = 1$
where $\mathbf{C}$ is the center of the ellipse.
From $ \mathbf{p_1, p_2, p_3}$ we can compute the normal vectors to the sides $\mathbf{p_1 p_2 , p_2 p_3 , p_3 p_1}$, let's call these $\mathbf{n_1, n_2, n_3} $ respectively.
Let the tangency points on these sides be $\mathbf{r_1, r_2, r_3}$ respectively.
Since the direction of the major axis is given as the angle $\theta$ it makes with $+x$ axis, then it has the form
$ Q = R D R^T $
where $ D = \begin{bmatrix} \dfrac{1}{a^2} && 0\\ 0 && \dfrac{1}{b^2} \end{bmatrix} $
And $ R = \begin{bmatrix} \cos \theta && - \sin \theta \\ \sin \theta && \cos \theta \end{bmatrix} $
Carrying out the multiplication, gives the following expression for $Q$:
$ Q = \begin{bmatrix} \dfrac{1}{a^2} \cos^2 \theta + \dfrac{1}{b^2} \sin^2 \theta && \sin \theta \cos \theta \left( \dfrac{1}{a^2} - \dfrac{1}{b^2} \right)\\ \sin \theta \cos \theta \left( \dfrac{1}{a^2} - \dfrac{1}{b^2} \right) && \dfrac{1}{a^2} \sin^2 \theta + \dfrac{1}{b^2} \cos^2 \theta \end{bmatrix} $
Now let the ratio of the major axis to the minor axis be $r$ then
$ a = r b $
Substituting this into the above equation gives
$ Q = \dfrac{1}{b^2} Q_0 $
where
$ Q_0 = \begin{bmatrix} \dfrac{1}{r^2} \cos^2 \theta + \sin^2 \theta && \sin \theta \cos \theta \left( \dfrac{1}{r^2} - 1 \right)\\ \sin \theta \cos \theta \left( \dfrac{1}{r^2} - 1 \right) && \dfrac{1}{r^2} \sin^2 \theta + \cos^2 \theta \end{bmatrix} $
Note that $Q_0$ is known.
Now the gradient vector at the tangency points $\mathbf{r_i}, i = 1,2,3 $ is given by
$ \mathbf{g_i} = 2 Q (\mathbf{r_i - C} ) $
And assuming the $\mathbf{n}_i $ are pointing outward from the triangle then we have
$ Q(\mathbf{r_i - C} ) = k_i \ \mathbf{n_i} $
From which
$ \mathbf{r_i - C} = k_i Q^{-1} \ \mathbf{n_i} $
Now let
$ P = Q^{-1} = b^2 Q_0^{-1} = b^2 P_0 $
Then
$ \mathbf{r_i - C} = k_i b^2 P_0 \mathbf{n}_i $
Substituting this into the equation of the ellipse, gives
$ k_i = \dfrac{1}{b \sqrt{ \mathbf{n}_i P_0 \mathbf{n}_i } }$
so that
$ \mathbf{r_i - C} = b \dfrac{ P_0 \mathbf{n_i}}{ \sqrt{ \mathbf{n}_i P_0 \mathbf{n}_i }} $
Pre-multiplying this with $\mathbf{n}_i^T $ gives
$ \mathbf{n_i}^T (\mathbf{r_i - C}) = b \sqrt{ \mathbf{n}_i P_0 \mathbf{n}_i } $
Now,
$\mathbf{n_i}^T (\mathbf{r_i - C}) = \mathbf{n_i}^T (\mathbf{r_i - p_i + p_i - C}) = \mathbf{n_i}^T (\mathbf{p_i - C} ) $, because $\mathbf{n_i}^T (\mathbf{r_i - p_i} ) = 0 $
Consequently, we now have the following equations
$ \mathbf{n_i}^T (\mathbf{p_i - C} ) = b \sqrt{ \mathbf{n}_i P_0 \mathbf{n}_i } , i = 1, 2, 3$
And this is a $3 \times 3$ linear system in the two coordinates of $\mathbf{C}$ and $b$ and can be readily solved.
This completes the specification of the ellipse.
The image below depicts the inellipse generated for the triangle with vertices $\mathbf{p_1} = (2,3), \mathbf{p_2} = (12,9) , \mathbf{p_3} = (5,17) $ using the above formulas. The angle of the major axis is specified as $60^\circ$ and the ratio of major to minor is $1.5$.