Found correct result in Matrix related Algebraic Equation by mistake

62 Views Asked by At

I'm working with computer graphics and I needed to figure out how something in an image was rotated so that I could match a camera angle and recreate the item in 3D.

The image shows the reference with the known vectors added. Reference image with vectors

The horizontal vector $\vec {x_0}$ can be normalised to $\begin{bmatrix}-1 & 0 & 0\end{bmatrix}$ and the other vector $\vec y$ can be normalised to $\begin{bmatrix}0.20720675587654114 & 0.9782971739768982 & 0\end{bmatrix}$. The original vector $\vec y_0$ is considered to be $\begin{bmatrix}0 & 1 & 0\end{bmatrix}$.

Considering $\vec {x_0}$ remains horizontal and $\vec y_0$ doesn't, I ascertained that there were two rotations, one around the x-axis ($\theta$) and one around the y-axis ($\gamma$) . I've also ascertained that an orthographic projection was being used. For the my purposes, I am not concerned with the final z coordinate.

I created rotation and projection matrices as follows:

$Rot_x = \begin{bmatrix}1 & 0 & 0\\0 & cos \theta & sin \theta\\0 & -sin \theta & cos \theta\end{bmatrix}$

$Rot_y = \begin{bmatrix}cos \gamma & 0 & sin \gamma\\0 & 1 & 0\\-sin \gamma & 0& cos \gamma\end{bmatrix}$

$Proj = \begin{bmatrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 0\end{bmatrix}$

Then, combined them:

$$\begin{align}{Rot_x \cdot Rot_y \cdot Proj} & = \begin{bmatrix} 1 & 0 & 0\\ 0 & cos \theta & sin \theta\\ 0 & -sin \theta & cos \theta \end{bmatrix} \begin{bmatrix} cos \gamma & 0 & sin \gamma\\ 0 & 1 & 0\\ -sin \gamma & 0& cos \gamma \end{bmatrix} \begin{bmatrix} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 0 \end{bmatrix}\\& = \begin{bmatrix} cos \gamma & 0 & sin \gamma\\ -sin \gamma sin \theta & cos \theta & cos \gamma sin \theta\\ -sin \gamma cos \theta & -sin \theta & cos \gamma cos \theta \end{bmatrix} \begin{bmatrix} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 0 \end{bmatrix}\\& = \begin{bmatrix} cos \gamma & 0 & 0\\ -sin \gamma sin \theta & cos \theta & 0\\ -sin \gamma cos \theta & -sin \theta & 0 \end{bmatrix} \end{align}$$

Writing the transformation in unit vector notation, I get:

$$\begin{align}\vec y & = ({y_{0x}} cos \gamma - {y_{0y}} sin \gamma sin \theta - {y_{0z}} sin \gamma cos \theta) \mathbf {\hat i} + ({y_{0x}} 0 + {y_{0y}} cos \theta - {y_{0z}} sin \theta) \mathbf {\hat j} + ({y_{0x}} 0 + {y_{0y}} 0 + {y_{0z}} 0) \mathbf {\hat k}\\& = ({y_{0x}} cos \gamma - {y_{0y}} sin \gamma sin \theta - {y_{0z}} sin \gamma cos \theta) \mathbf {\hat i} + ({y_{0y}} cos \theta - {y_{0z}} sin \theta) \mathbf {\hat j} \end{align}$$

Substituting in values from $\vec y$ and $\vec y_0$ we get:

$$\begin{align} 0.20720675587654114 \mathbf {\hat i} + 0.9782971739768982 \mathbf {\hat j} & = (0 cos \gamma - 1 sin \gamma sin \theta - 0 sin \gamma cos \theta) \mathbf {\hat i} + (1 cos \theta - 0 sin \theta) \mathbf {\hat j}\\ & = -(sin \gamma sin \theta) \mathbf {\hat i} + (cos \theta) \mathbf {\hat j}\ \end{align}$$

With this equation, $\theta$ and $\gamma$ should be able to be found (using the identity $sin \theta = \sqrt{1-{cos{^2}\theta}}$) by the equations:

$$\begin{align} cos \theta & = 0.9782971739768982\\ \theta & = cos^{-1}(0.9782971739768982)\\ -(sin \gamma sin \theta) & = 0.20720675587654114\\ sin \gamma & = \frac{0.20720675587654114}{-sin \theta}\\ sin \gamma & = \frac{0.20720675587654114}{\pm \sqrt{1-0.9782971739768982^2}}\\ \gamma & = sin^{-1}\left(\frac{0.20720675587654114}{\pm \sqrt{1-0.9782971739768982^2} }\right) \end{align}$$

However, I made a mistake and did the following, which returned the correct angles: $$\begin{align} -sin \theta & = 0.9782971739768982\\ sin \theta & = -0.9782971739768982\\ \theta & = sin^{-1}(-0.9782971739768982)\\ -(sin \gamma sin \theta) & = 0.20720675587654114\\ sin \gamma & = \frac{0.20720675587654114}{-sin \theta}\\ sin \gamma & = \frac{0.20720675587654114}{0.9782971739768982}\\ \gamma & = sin^{-1}\left(\frac{0.20720675587654114}{0.9782971739768982 }\right) \end{align}$$

This gave the following results, which rotated a a plane correctly (with some sign adjustments due to the program's rotational orientations):

$$\begin{align} \theta & = -78.04128901169878^\circ\\ \gamma & = 12.22806234616057^\circ \end{align}$$

Obviously, I've made a mistake somewhere in verifying my results. Can anyone see where I've made the mistake? As I said, the mistaken equations yielded correct values, yet the "correct" equations yield a domain error.

1

There are 1 best solutions below

0
On BEST ANSWER

So, upon further investigation, I've found that my original result looked right, but wasn't. In disregarding the z-axis, I disguarded vital information, making the problem unsolvable. Therefore, $\vec y$ is not normalised as $\begin{bmatrix}0.20720675587654114 & 0.9782971739768982 & 0\end{bmatrix}$, but is closer to a normalisation of $\begin{bmatrix}0.20720675587654114 & 0.9782971739768982 & {z_y}\end{bmatrix}$. I've generalised this as $\begin{bmatrix}A{X_y} & A{Y_y} & {z_y}\end{bmatrix}$ where $A$ scales ${X_y}$ and ${Y_y}$ such that $\begin{bmatrix}A{X_y} & A{Y_y} & {z_y}\end{bmatrix}$ is a unit vector.

Reference with extra vector in red

Going back to the original reference image, I've marked a third known vector in red. The original value of this vector $\vec {z_0}$ can be normalised to $\begin{bmatrix}0 & 0 & 1\end{bmatrix}$. I've generalised $\vec {z}$ as $\begin{bmatrix}B{X_z} & B{Y_z} & {z_z}\end{bmatrix}$ with $B$ serving a similar purpose to $A$ in $\vec y$.

Expanding the matrix multiplication with these two vectors, I get:

$$\begin{align} A{X_y} & = -{y_{y0}}{sin \gamma}{sin \theta}\\ A{Y_y} & = {y_{y0}}{cos \theta}\\ {z_y} & = {y_{y0}}{cos \gamma}{sin \theta}\\ B{X_z} & = -{z_{z0}}{sin \gamma}{cos \theta}\\ B{Y_z} & = -{z_{z0}}{sin \theta}\\ {z_z} & = {z_{z0}}{cos \gamma}{cos \theta}\\ \end{align}$$

Substituting known initial values: $$\begin{align} {y_{y0}} & = 1\\ {z_{z0}} & = 1\\ \\ A{X_y} & = -{sin \gamma}{sin \theta}\\ A{Y_y} & = {cos \theta}\\ {z_y} & = {cos \gamma}{sin \theta}\\ B{X_z} & = -{sin \gamma}{cos \theta}\\ B{Y_z} & = -{sin \theta}\\ {z_z} & = {cos \gamma}{cos \theta}\\ \end{align}$$

Next, I found equivalences for the ratios of each vector: $$\begin{align} \frac{A{X_y}}{A{Y_y}} & = \frac{-{sin \gamma}{sin \theta}}{{cos \theta}}\\ \frac{{X_y}}{{Y_y}} & = -{sin \gamma}{tan \theta}\\ \\ \frac{B{X_z}}{B{Y_z}} & = \frac{-{sin \gamma}{cos \theta}}{-{sin \theta}}\\ \frac{{X_z}}{{Y_z}} & = \frac{{sin \gamma}}{{tan \theta}}\\ \end{align}$$

Next, I multiplied $\frac{{X_z}}{{Y_z}}$ by a value $C$ such that: $$\begin{align} C{\frac{{X_z}}{{Y_z}}} & = \frac{{X_y}}{{Y_y}}\\ C & = {\frac{{X_y}{Y_z}}{{Y_y}{X_z}}} \end{align}$$

This gives me the following equivalence, which can be simplifed thus: $$\begin{align} \frac{C{sin \gamma}}{{tan \theta}} & = -{sin \gamma}{tan \theta}\\ \frac{C}{{tan \theta}} & = -{tan \theta}\\ {C} & = -{{tan^2} \theta}\\ {-C} & = {{tan^2} \theta}\\ \sqrt{-C} & = {tan \theta}\\ {tan^{-1}}\sqrt{-C} & = \theta\\ \end{align}$$

Since: $C = {\frac{{X_y}{Y_z}}{{Y_y}{X_z}}}$

Then: $\theta = {tan^{-1}}{\sqrt{-\frac{{X_y}{Y_z}}{{Y_y}{X_z}}}}$

Given our known values: $$\begin{align} {X_y} & = 0.20720675587654114\\ {Y_y} & = 0.9782971739768982\\ \\ {X_z} & = 0.1048736646771431\\ {Y_z} & = -0.99448561668396\\ \end{align}$$

Then: $$\begin{align} \theta & = {tan^{-1}}{\sqrt{-\frac{(0.20720675587654114)(-0.99448561668396)}{(0.9782971739768982)(0.1048736646771431)}}}\\ \theta & = {tan^{-1}}{\sqrt{2.008469191868533}}\\ \theta & = {tan^{-1}}{1.4172047106429377}\\ \theta & = 0.9563122633179668\\ \theta & = {54.79265658472295}^{\circ} \end{align}$$

And: $$\begin{align} \frac{{sin \gamma}}{1.4172047106429377} & = \frac{0.1048736646771431}{-0.99448561668396}\\ {sin \gamma} & = \frac{(0.1048736646771431)(1.4172047106429377)}{-0.99448561668396}\\ {sin \gamma} & = \frac{(0.1048736646771431)(1.4172047106429377)}{-0.99448561668396}\\ {sin \gamma} & = -0.14945158492932506\\ \gamma & = -0.15001360524175628\\ \gamma & = -8.595146449894239^\circ\\ \end{align}$$