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

I have a vector $v$ and two non-orthogonal vectors $p$ and $q$. I'm trying to decompose $v$ in terms of $p$ and $q$, resulting in two variables $i$ and $j$ such that $i~p + j~q = v$. After trying a few different things I settled on using the law of sines as follows (with $\cdot$ being the dot product of two vectors and $||v||$ being the length of $v$):

$x = \frac{||v||}{\sin (p \cdot q)}$

$i = \frac{x ~ \sin(q \cdot v)}{||p||}$

$j = \frac{x ~ \sin(v \cdot p)}{||q||}$

Unfortunately, this only gives me the absolute value of $i$ and $j$. For example, decomposing (6,0) in (0,1) and (3,2) produces 4 and 2, whereas the correct answer is -4 and 2. Can anyone tell me how to get the correct signs for $i$ and $j$?

share|cite|improve this question
Sorry, but those formulas aren't correct. – anon Jul 26 '11 at 13:48
How so? They're directly derived from the law of sines, which states that $\frac{a}{\sin A} = \frac{b}{\sin B} = \frac{c}{\sin C}$. $a = |i| ~ ||p||$, so $|i| = \frac{a}{||p||}$. $a = \frac{c \sin A}{\sin C}$. $A = q \cdot v$. $C = p \cdot q$. $c = ||v||$. Therefore $|i| = \frac{||v|| \sin (q \cdot v)}{||p|| \sin (p \cdot q)}$ Perhaps I'm missing something, but I don't see any mistakes in my calculations. – FalconNL Jul 26 '11 at 14:06
possible duplicate of Length of Perpendicular/Parallel Vectors – joriki Jul 26 '11 at 14:09
@FalconNL: You're misusing the dot product. See Wikipedia for the correct angle formula. – anon Jul 26 '11 at 14:11
up vote 1 down vote accepted

We're obviously working in $\mathbb{R}^2$. Write $\vec{x}=(x_1,x_2)$, $\vec{p}=(p_1,p_2)$, $\vec{q}=(q_1,q_2)$. You want to solve for the coefficients in the following decomposition (which only works if $\vec{p}\not\|\vec{q}$, i.e. they aren't parallel so that they form a valid basis of $\mathbb{R}^2$):

$$\vec{x} = a\vec{p}+b\vec{q}.$$

We can write this in matrix form as follows:

$$\begin{pmatrix} p_1 & q_1\\ p_2 & q_2 \end{pmatrix} \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} x_1\\ x_2 \end{pmatrix}.$$

Since the two basis vectors aren't parallel the determinant of the above matrix is nonzero, hence the matrix is nonsingular. So multiply both sides by the inverse matrix to solve for the coefficients:

$$\begin{pmatrix} a \\ b \end{pmatrix} = \frac{1}{p_1q_2-p_2q_1}\begin{pmatrix} q_2 & -q_1\\ -p_2 & p_1 \end{pmatrix} \begin{pmatrix} x_1\\ x_2 \end{pmatrix}.$$

Using the cross product and the vector $\vec{k}=(0,0,1)$, and interpreting all the original vectors as ones from the $xy$-plane of $\mathbb{R}^3$, we can then decompose $\vec{x}$ succinctly as

$$\vec{x}=\left(\frac{(\vec{x}\times\vec{q})\cdot \vec{k}}{(\vec{p}\times\vec{q})\cdot\vec{k}} \right)\vec{p}+\left(\frac{(\vec{p}\times\vec{x})\cdot \vec{k}}{(\vec{p}\times\vec{q})\cdot\vec{k}}\right)\vec{q}.$$

share|cite|improve this answer
This works brilliantly, thanks. – FalconNL Jul 26 '11 at 14:14

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.