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\$
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\$
  • 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 Mar 26 '14 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 Mar 26 '14 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 Mar 26 '14 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 Mar 26 '14 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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