Advertisement Jump to content
Sign in to follow this  

'Remove' direction from velocity

This topic is 1095 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a vector A, which represents a velocity, and a normalized vector B, which represents a direction.

I'd like to modify A, so that only the part of the velocity that doesn't go in the direction of B, remains.




A = (175,25,33)

B = (0,1,0)

Result = (175,0,33) -- Only x and z remain



A = (175,25,33)

B = (1,0,0)

Result = (0,25,33) -- Only y and z remain



A = (175,25,33)

B = (-0.116872,0.943617,0.309723)

Result = ?


How can I accomplish this?

I suppose I'd have to 'map' the velocity A onto a plane orthogonal to B, I'm just not sure how.

Another idea I've had is:

1) Set C = (0,1,0)

2) Calculate quaternion rotation from B to C using the cross product

3) Rotate A by the result

4) Set A.y = 0

5) Rotate A by the inverse of the result


Would that work?

Share this post

Link to post
Share on other sites
Vector rejection(Vector A, Vector B) {
  return A - B * dot_product(A, B); // This assumes B's length is 1.

EDIT: I changed the name, following Arjan's comment. Edited by Álvaro

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!