# 'Remove' direction from velocity

This topic is 914 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.

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.

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002286
×