Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, I have a linear equation, and I need to solve for some variables in said equation. However, since I don't know much about matrices, I don't know how to solve for the variables. The equation in question is the one from the Wikipedia page on perspective projection. It is as follows:


I know $a$, $c$, and $d$, but I need to find $\theta$. Let's say that $a$ is (5,0,0), $c$ is (10,0,0), and $d$ is (10,5,0). How, then, would I solve for $\theta$?

share|cite|improve this question
is $b = (10, 0 , 0)$ what you are calling $c$? Regards – Amzoti Jan 23 '13 at 23:02
@Amzoti Oh, oops! Yes. – Steven Fontaine Jan 23 '13 at 23:13
up vote 2 down vote accepted

You have two vectors, $d$ and $a-c$, and are trying to solve for a rotation matrix $R$ that maps $a-c$ to $d$: $$d = R(a-c).$$

Here you've written $R$ as a composition of rotations using Euler angles. Before we worry about the Euler angles, let's find $R$.

Notice that this equation only has a solution when $d$ and $a-c$ have the same norm (which your example vectors do not), and that even when a solution exists, it is not unique.

One way to overcome these difficulties is to find the "best possible" rotation from $a-c$ to $d$, i.e.,

$$\min_R \|d-R(a-c)\|\quad \textrm{s.t.}\quad R^TR=1, \det R=1,$$

which always has a solution, given by the Kabsch algorithm. In this case, where our data set consists of only one pair of vectors, we can take a shortcut. The axis of the optimal rotation is given by $$\hat n = \frac{(a-c) \times d}{\|(a-c) \times d\|}$$ and the angle by $$\theta = \arccos\left(\frac{a-c}{\|a-c\|}\cdot\frac{d}{\|d\|}\right).$$

From this axis and angle, you can find $R$ using the Rodrigues rotation formula, and from there, compute the Euler angles. See for more details.

EDIT: Notice that the above assumes that $d$ and $a-c$ have non-zero norm, and are not colinear. These special corner cases require separate treatment.

share|cite|improve this answer
"I don't know much about matrices." I have no clue on the algorithms to which you referred, and little idea of most of the terminology which you used.. Could you please elaborate some and/or provide links where I can find some explanation? – Steven Fontaine Jan 24 '13 at 2:33
Sure. Does it make sense how to compute $\hat n$ and $\theta$? Once you have those, use the formulas in… to get the matrix $R$ ($A$ on Wikipedia) and then use… to get $\theta_x, \theta_y, \theta_z$. – user7530 Jan 24 '13 at 3:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.