Poftethef9t

2022-06-27

Let's say we define the orientation of the ellipsoid from its major axis (the largest axis of the ellipsoid). Assuming the 3 axes of the ellipsoid to be on the three coordinates with lengths of $a$, $b$ and $c$ along each axis (with $a\ge b$ and $a\ge c$), then only a single affine transformation (to a sphere) is necessary:
$\left[\begin{array}{cccc}a& 0& 0& 0\\ 0& b& 0& 0\\ 0& 0& c& 0\\ 0& 0& 0& 1\end{array}\right]$
Now, if we first rotate the major axis by $\theta$ from the first axis towards the second axis, and then rotate it by $\varphi$ from the (rotated) first axis towards the third axis, the combined affine transformation becomes:
$\left[\begin{array}{cccc}a& 0& 0& 0\\ 0& b& 0& 0\\ 0& 0& c& 0\\ 0& 0& 0& 1\end{array}\right]\left[\begin{array}{cccc}cos\theta & -sin\theta & 0& 0\\ sin\theta & cos\theta & 0& 0\\ 0& 0& 1& 0\\ 0& 0& 0& 1\end{array}\right]\left[\begin{array}{cccc}cos\varphi & 0& -sin\varphi & 0\\ 0& 1& 0& 0\\ sin\varphi & 0& cos\varphi & 0\\ 0& 0& 0& 1\end{array}\right]$
Is the multiplied matrix (from left to right) the correct affine transformation that must go into the equations in the links above?

Christina Ward

Expert

Let's say you have an ellipsoid centered at $\stackrel{\to }{c}$ with semi-principal axes ${\stackrel{\to }{r}}_{1}$, ${\stackrel{\to }{r}}_{2}$, and ${\stackrel{\to }{r}}_{3}$:
${\stackrel{\to }{r}}_{1}=\left[\begin{array}{c}{r}_{11}\\ {r}_{21}\\ {r}_{31}\end{array}\right],\phantom{\rule{2em}{0ex}}{\stackrel{\to }{r}}_{2}=\left[\begin{array}{c}{r}_{12}\\ {r}_{22}\\ {r}_{32}\end{array}\right],\phantom{\rule{2em}{0ex}}{\stackrel{\to }{r}}_{3}=\left[\begin{array}{c}{r}_{13}\\ {r}_{23}\\ {r}_{33}\end{array}\right]$
The surface of the ellipsoid passes through points $\stackrel{\to }{c}±{\stackrel{\to }{r}}_{1}$, $\stackrel{\to }{c}±{\stackrel{\to }{r}}_{2}$ and $\stackrel{\to }{c}±{\stackrel{\to }{r}}_{3}$.
The semi-principal axes are all perpendicular: ${\stackrel{\to }{r}}_{1}\cdot {\stackrel{\to }{r}}_{2}=0$, ${\stackrel{\to }{r}}_{1}\cdot {\stackrel{\to }{r}}_{3}=0$, and ${\stackrel{\to }{r}}_{2}\cdot {\stackrel{\to }{r}}_{3}=0$.
The axis-aligned bounding box for the above ellipsoid is defined by
$\begin{array}{c}x={c}_{x}±\sqrt{{r}_{11}^{2}+{r}_{12}^{2}+{r}_{13}^{2}}\\ y={c}_{y}±\sqrt{{r}_{21}^{2}+{r}_{22}^{2}+{r}_{23}^{2}}\\ z={c}_{z}±\sqrt{{r}_{31}^{2}+{r}_{32}^{2}+{r}_{33}^{2}}\end{array}$
Note that this applies also to the case where the homogenous transformation matrix M that transforms the unit sphere to the ellipsoid is
$\mathbf{M}=\left[\begin{array}{cccc}{r}_{11}& {r}_{12}& {r}_{13}& {c}_{x}\\ {r}_{21}& {r}_{22}& {r}_{23}& {c}_{y}\\ {r}_{31}& {r}_{32}& {r}_{33}& {c}_{z}\\ 0& 0& 0& 1\end{array}\right]$

Brenden Tran

Expert

Here is full soluion:
We can describe the transformation of the unit sphere to the above ellipsoid using
$\begin{array}{}\text{(1)}& \stackrel{\to }{p}\left(u,v,w\right)=\stackrel{\to }{p}\left(\stackrel{\to }{t}\right)=\stackrel{\to }{c}+u{\stackrel{\to }{r}}_{1}+v{\stackrel{\to }{r}}_{2}+w{\stackrel{\to }{r}}_{3}=\stackrel{\to }{c}+\mathbf{R}\stackrel{\to }{t}\end{array}$
where $\stackrel{\to }{t}=\left(u,v,w\right)$ fulfills
$‖\stackrel{\to }{t}‖=1\phantom{\rule{2em}{0ex}}\phantom{\rule{thickmathspace}{0ex}}⟺\phantom{\rule{thickmathspace}{0ex}}\phantom{\rule{2em}{0ex}}{u}^{2}+{v}^{2}+{w}^{2}=1$
on the surface of the ellipsoid, and
$‖\stackrel{\to }{t}‖<1\phantom{\rule{2em}{0ex}}\phantom{\rule{thickmathspace}{0ex}}⟺\phantom{\rule{thickmathspace}{0ex}}\phantom{\rule{2em}{0ex}}{u}^{2}+{v}^{2}+{w}^{2}<1$
within the ellipsoid, and matrix R has the semi-principal axes as column vectors,
$\mathbf{R}=\left[\begin{array}{ccc}{\stackrel{\to }{r}}_{1}& {\stackrel{\to }{r}}_{2}& {\stackrel{\to }{r}}_{3}\end{array}\right]=\left[\begin{array}{ccc}{r}_{11}& {r}_{12}& {r}_{13}\\ {r}_{21}& {r}_{22}& {r}_{23}\\ {r}_{31}& {r}_{32}& {r}_{33}\end{array}\right]$
Essentially, we scale the unit sphere by the semi-principal axes, rotate it to the new orientation, and translate the center.
The above operation is invertible, if the ellipsoid is not degenerate; that is, if $‖{\stackrel{\to }{r}}_{1}‖>0$, $‖{\stackrel{\to }{r}}_{2}‖>0$, and $‖{\stackrel{\to }{r}}_{3}‖>0$.
Since rotation matrices are orthonormal, its inverse is its transpose. To counteract the scaling, we scale by the inverses of the semi-principal axes.
The scaling vectors are now row vectors of the transformation matrix, with lengths inverse to the corresponding semi-principal axis length; i.e.
${\stackrel{\to }{s}}_{n}={\left(\frac{{\stackrel{\to }{r}}_{n}}{{‖{\stackrel{\to }{r}}_{n}‖}^{2}}\right)}^{T},\phantom{\rule{2em}{0ex}}n=1,2,3$
so that
$‖{\stackrel{\to }{s}}_{n}‖={‖{\stackrel{\to }{r}}_{n}‖}^{-1},\phantom{\rule{2em}{0ex}}n=1,2,3$
i.e.
${\stackrel{\to }{s}}_{1}=\frac{{\stackrel{\to }{r}}_{1}}{{‖{\stackrel{\to }{r}}_{1}‖}^{2}}=\left[\begin{array}{ccc}{s}_{11}& {s}_{12}& {s}_{13}\end{array}\right]$
${\stackrel{\to }{s}}_{2}=\frac{{\stackrel{\to }{r}}_{2}}{{‖{\stackrel{\to }{r}}_{2}‖}^{2}}=\left[\begin{array}{ccc}{s}_{21}& {s}_{22}& {s}_{23}\end{array}\right]$
${\stackrel{\to }{s}}_{3}=\frac{{\stackrel{\to }{r}}_{3}}{{‖{\stackrel{\to }{r}}_{3}‖}^{2}}=\left[\begin{array}{ccc}{s}_{31}& {s}_{32}& {s}_{33}\end{array}\right]$
${s}_{ij}=\frac{{r}_{ji}}{{r}_{1i}^{2}+{r}_{2i}^{2}+{r}_{3i}^{2}},\phantom{\rule{2em}{0ex}}i=1,2,3;\phantom{\rule{thickmathspace}{0ex}}j=1,2,3$
$\mathbf{S}=\left[\begin{array}{ccc}{s}_{11}& {s}_{12}& {s}_{13}\\ {s}_{21}& {s}_{22}& {s}_{23}\\ {s}_{31}& {s}_{32}& {s}_{33}\end{array}\right]$
Now,
$\begin{array}{}\text{(2)}& \stackrel{\to }{t}\left(\stackrel{\to }{p}\right)={\stackrel{\to }{s}}_{1}\cdot \left(\stackrel{\to }{p}-\stackrel{\to }{c}\right)+{\stackrel{\to }{s}}_{2}\cdot \left(\stackrel{\to }{p}-\stackrel{\to }{c}\right)+{\stackrel{\to }{s}}_{3}\cdot \left(\stackrel{\to }{p}-\stackrel{\to }{c}\right)=\mathbf{S}\left(\stackrel{\to }{p}-\stackrel{\to }{c}\right)\end{array}$
Essentially, (1) and (2) are the inverse of each other.
If you insist on using Euler or Tait-Bryan angles or other similar angular convention, I recommend you use them to calculate the semi-principal axes ${\stackrel{\to }{r}}_{1}$, ${\stackrel{\to }{r}}_{2}$, and ${\stackrel{\to }{r}}_{3}$ only, and then apply the above vector solution.

Do you have a similar question?