# Finding the space between two vectors?

Could someone explain why the formula: $$\theta = \cos^ {-1}(a \cdot b)$$ provides the angle between vector $a$ and vector $b$? All the online resources seem to explain how to find the angle, but not why the method works.

Resources I looked at: http://chemistry.about.com/od/workedchemistryproblems/a/scalar-product-vectors-problem.htm

http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm

http://en.m.wikipedia.org/wiki/Dot_product

-
How do you define the dot product? – mixedmath♦ May 23 '12 at 18:31
You can take this as a definition of angle. In any case, this is the law of cosines. – Qiaochu Yuan May 23 '12 at 18:33
Multiplying corresponding entries of the vectors and then summing the products. – user26649 May 23 '12 at 18:33
@QiaochuYuan I suspected it to have something to do with the cosine law, but I don't see any mention of the third side. Using cosine law, wouldn't $\theta = \cos^{-1}\left(\frac{c^2 - a^ 2 - b^2}{-2ab}\right)$ – user26649 May 23 '12 at 18:39

2
The vectors must be unit vectors. Otherwise it's $\cos^{-1}\left( \dfrac{a.b}{\|a\| \|b\|} \right)$ – Robert Israel May 23 '12 at 18:41
show 1 more comment

## 3 Answers

The dot product can be derived from the cosine law. $$c^2=a^2+b^2-2ab\cos(C)$$ where C is the angle between $a$ and $b$. If you consider $a$ and $b$ as your vectors, then side $c$ can be represented as $(b-a)$. So (noting that I'm talking about distances)

$$|b-a|^2=|a|^2+|b|^2-2|a||b|cos(C)$$ $${(b_x-a_x)}^2+{(b_y-a_y)}^2={a_x}^2+{a_y}^2+{b_x}^2+{b_y}^2-2|a||b|cos(C)$$ $$({b_x}^2-2a_xb_x+{a_x}^2)+({b_y}^2-2a_yb_y+{a_y}^2)={a_x}^2+{a_y}^2+{b_x}^2+{b_y}^2-2|a||b|cos(C)$$ cancel out the squared terms and you get $$-2(a_xb_x+a_yb_y)=-2|a||b|cos(C)$$ $$a_xb_x+a_yb_y=|a||b|cos(C)$$ $$a\cdot b=|a||b|cos(C)$$ which gives you a nice way of getting the angle between vectors if you only have their components, by the simple rearrangement: $$C=\arccos(\frac{a\cdot b}{|a||b|})$$

It's less obvious why this works in the general dimensional case (and not just 2D), but a good place to start is to notice that any two vectors can always be put in a plane, and showing that expressing the $(x,y)$ of the plane in terms of the higher-dimensional vector components, then applying this calculation makes all the math come out okay.

-

Thank You Robert! – user26649 May 23 '12 at 19:05

A combination of linear algebra and geometry can be useful. If $R$ is a rotation matrix, it satisfies $R^TR=I_n$, where $I_n$ is the $n\times n$ identity matrix. Assume $v,w$ are unit vectors. We compute

$$Rv\cdot Rw=(Rv)^T(Rw)=v^T(R^TR)w=v^TI_nw=v^Tw=v\cdot w$$

using matrix transpose properties. Thus the dot product is rotation-invariant. Rotations act transitively, which for our purposes means that given $v,w$ we can find a rotation $R$ so that $Rv=e_1$ is the first basis unit vector. After that we rotate around the $x$-axis so that $Rw$ becomes a vector on the $xy$-plane (while $Rv=e_1$ remains unchanged), and we are reduced to the case of $\Bbb R^2$. Here,

$$(1,0)\cdot(\cos\theta,\sin\theta)=\cos\theta,$$

as desired (where $\theta$ is the angle between the second vector and the $x$-axis, or equivalently $e_1$).

-

We know that

$$\cos(\alpha-\beta)=\cos(\alpha)\cos(\beta)+\sin(\alpha)\sin(\beta)$$

Now let $\alpha$ be the angle between $a$ and the $x$-axis, and $\beta$ between $b$ and the $x$-axis. From the definition of sin and cos you got:

$$\cos(\alpha-\beta)=\frac{a_1}{|a|}\frac{b_1}{|b|}+\frac{a_2}{|a|}\frac{b_2}{|b|}=\frac{ab}{|a||b|}$$

Since the angle between a and b is $\theta=\alpha-\beta$, you got

$$\theta=\arccos\left(\frac{ab}{|a||b|}\right)$$

QED

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 34, "mathjax_display_tex": 14, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9198631048202515, "perplexity_flag": "head"}