<s>[INST] Finding center and rotation angle of ellipse that contains three points Given three points $p_1, p_2, p_3 \in \mathbb{R}^2$, and an ellipse with shape parameters $(a,b)$ (the semi-major and semi-minor), is it possible to determine, if they exist, a center $c \in \mathbb{R}^2$ and a rotation angle $\theta \in [0, \pi]$, such that the ellipse centered at $c$ rotated by $\theta$ contains $p_1, p_2, p_3$?
In other words, let
$$E(p, \theta)=\dfrac{(p_x\cos{\theta} + p_{y}\sin{\theta})^2}{a^2} + \dfrac{(p_x\sin{\theta} -p_y\cos{\theta})^2}{b^2}$$
I want to determine $c\in \mathbb{R}^2$ and $\theta \in [0, \pi]$, such that:
\begin{equation}
E(p_1-c, \theta) = 1\\
E(p_2-c, \theta) = 1\\
E(p_3-c, \theta) = 1
\end{equation}
 [/INST] Let the three points be $A,B,C$.  The idea of this solution is to transform $\triangle ABC$ into an equilateral triangle with vertices $(0,0), (1,0), (\dfrac{1}{2}, \dfrac{\sqrt{3}}{2} ) $
There are three possible arrangements for the vertices in terms of the pre-images of the equilateral triangle vertices:
$A , B , C$
$A , C , B$
$B , C , A$
The affine transformation is
$f(P) = T (p - V_1)$
where $V_1$ is the first vertex.
Take for example the first arrangement, then
$ T \begin{pmatrix} B- A && C - A \end{pmatrix} = \begin{pmatrix} 1 && \dfrac{1}{2} \\ 0 && \dfrac{\sqrt{3}}{2} \end{pmatrix} $
From which, we can calculate the transformation matrix $T$.
Now, we'll pass an ellipse in standard orientation through the three vertices of the equilateral triangle, let the center of the ellipse be $ C = (1/2 , c )$, then the equation of ellipse
$ \dfrac{(x - (1/2))^2}{ a^2 } + \dfrac{(y - c)^2} {b^2} = 1 $
The points through which this ellipse passes are $(0,0), (1,0), (\dfrac{1}{2}, \dfrac{\sqrt{3}}{2} ) $
Substituting the first is the same as substituting the second, they both give us
$ \dfrac{1}{4 a^2} + \dfrac{c^2}{ b^2} = 1 $
Substituting the third point,
$ \dfrac{ (\sqrt(3)/2 - c ) ^2}{  b^2 }= 1 $
So that  $ b = sqrt(3)/2 - c $
Now define the matrix
$Q = \begin{bmatrix} \dfrac{1}{a^2} &&   0 \\ 0  && \dfrac{1}{b^2} \end{bmatrix}$
The pre-transformation Q is obtained as follows:
The position vectors are related by $r = T (r' - A)$  where $r'$ is the position vector of the original points, and $r$ is the position vector after applying the transformation.
Now, we have the ellipse that passes through the three vertices of the equilateral triangle is given by
$ (r - C)^T Q (r - C) = 1 $
where $C = (1/2, c )$
Substitute $r$
$(T (r' - A) - C )^T Q (T (r' - A) - C) = 1 $
And this simplifies to
$ (r' - A - T^{-1} C ) ^T T^T Q T ( r' - A - T^{-1} C ) = 1 $
so our $Q' = T^T Q T$
Expanding,
$Q' = \begin{bmatrix} (1/a^2) t_1^2 + (1/b^2) t_3^2 &&     (1/a^2) t_1 t_2 +(1/b^2) t_3 t_4 \\(1/a^2) t_1 t_2 +(1/b^2) t_3 t_4 && (1/a^2) t_2^2 + (1/b^2) t_4^2 \end{bmatrix} $
where $T = \begin{bmatrix} t_1 && t_2 \\ t_3 && t_4 \end{bmatrix} $
we want the eigenvalues of $Q'$ to be $ 1/a_e^2 $ and $  1/b_e^2 $ where $a_e, b_e$ are the given semi-axes lengths of the ellipse.
so using the trace and the determinant, we obtain
$ \dfrac{1}{a^2} (t_1^2 + t_2^2) + \dfrac{1}{b^2} (t_3^2 + t_4^2 ) = \dfrac{1}{a_e^2} + \dfrac{1}{b_e^2} \hspace{30pt}(1) $
and for the determinant expression, it simplifies to
$ \dfrac{1}{a b} | t_1 t_4 - t_2 t_3 | = \dfrac{1}{a_e b_e} \hspace{30pt} (2) $
Now recall that
$ \dfrac{1}{4 a^2} + \dfrac{c^2}{ b^2} = 1 $
and that
$ c = \dfrac{\sqrt{3}}{2} - b $
substituting this last equation in the previous one, gives
$ \dfrac{1}{4 a^2} + \dfrac{3}{4 b^2} - \dfrac{\sqrt{3}}{b} = 0 \hspace{30pt}(3)$
This system of equations $(1), (2), (3)$ in the two unknowns $a , b$ is overdetermined.  So the strategy to solve it is to solve $(1), (2)$ and then check that $(3)$ is satisfied.  Once all three equations are satisified then we have our ellipse, and we can compute the center and the $Q'$ matrix from which by diagonalizing we can compute $\theta $.
</s>