# '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.

## 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.

Examples:

#1

A = (175,25,33)

B = (0,1,0)

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

#2

A = (175,25,33)

B = (1,0,0)

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

#3

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 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 on other sites

rejection

!!

I'm really glad I finally have something to call that concept now.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015434
×