4
\$\begingroup\$

Couldn't find a clear enough answer on Google.

I know what vectors are. But what does it mean to project a vector onto another, and what is it used for in games?

\$\endgroup\$
1

1 Answer 1

6
\$\begingroup\$

Vector projection means finding the components of vector a that are in the same direction of vector b. Check my answer here for how to do it.

enter image description here

Not only vector projection is important in game dev but vector decomposition in general, where you have a vector and you need to decompose it into 3(or 2) separate vectors in the u,v,w directions.

For example in order to find a local frame of reference (read: object space/coordinates) you often need to find three linearly independent vectors which form the frame of reference. You can start by finding the projection on X axis (or the local u direction) and then continue with cross product to find the third vector. The final step would to cross product the result two vectors from the previous operations.

Another situation in physics simulation you will often have force vectors that you need to find their sum in each direction, you cannot do that unless you do vector decomposition.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Thanks for answering. What do you mean by 'finding the components of vector a that are in the same direction as vector b`? What 'components'? The 'direction' means the angle, right? \$\endgroup\$
    – Aviv Cohn
    Commented Mar 26, 2014 at 13:44
  • \$\begingroup\$ @Prog when you project a on b, the result vector say c , will have the same (x,y) components of b. That it will have the same direction as b but different length. \$\endgroup\$
    – concept3d
    Commented Mar 26, 2014 at 13:53
  • 1
    \$\begingroup\$ In the illustration, is the perpendicular line to b - vector c? If so, than as I said it is perpendicular to it, and not the same direction as b. What am I missing? \$\endgroup\$
    – Aviv Cohn
    Commented Mar 26, 2014 at 18:56
  • 1
    \$\begingroup\$ another question: By components do you mean the x and y values of the vector? If so, than each 2d vector has only two components by definition. However you said 'finding the components of vector a that are in the same direction as vector b'. I still don't get what you mean by that. vector a has two certain components, it's x and y values, and so does vector b. these components also define the direction. So how 'components of vector a' be the same 'direction' as 'components of vector b'? Sorry for taking long to understand. \$\endgroup\$
    – Aviv Cohn
    Commented Mar 26, 2014 at 19:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .