# 3d Math Primer book equation derivation - Projecting One vector onto another

I'm reading the book 3d Math Primer for Graphics and Game Development 1st edition by Fletcher Dunn and Ian Parberry. On page 61 there's this:

How does it derive $$v_{||}$$ there? It doesn't follow from what preceded this point in the book, unless I'm missing something. Also I'm not sure, is $$n$$ supposed to be unit vector here? This should probably be in the errata but I didn't find anything. Anyway, how did he deduce this equation? Thanks in advance.

## 2 Answers

Since v∥ is parallel to n, it can be expressed as some multiple of n. The multiple is the ratio of the length of v∥ to the length of n. The n vector doesn’t have to be normalized, but if it is, then |n| is 1, so the equation becomes v∥ = n * |v∥|.

Since we have:

$$\pmb{v}_{\parallel} \parallel \pmb{n},$$

then:

$$\pmb{v}_{\parallel} = k\pmb{n}$$

We want that the length of $$\pmb{v}_{\parallel}$$ is $$\|\pmb{v}_{\parallel}\|$$, then:

$$\|\pmb{v}_{\parallel}\| =|k|\|\pmb{n}\| \implies |k| = \frac{\|\pmb{v}_{\parallel}\|}{\|\pmb{n}\|}$$

Then the sign of $$k$$ is simply chosen to match the direction of $$\pmb{v}$$ (if the angle between $$\pmb{v}$$ and $$\pmb{n}$$ is more than 90 degrees, the sign is negative, otherwise it is positive).