'Remove' direction from velocity

Started by
2 comments, last by Nypyren 8 years, 3 months ago

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?

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

Just to add to Alvaro's comment: projection of A onto B gives you all of A in the direction of B. This is why he/she subtracts that projection from A. The Wikipedia page on vector projection calls this the rejection of A from B: https://en.wikipedia.org/wiki/Vector_projection

rejection


!!

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

This topic is closed to new replies.

Advertisement