How to get a 3D vector in the same direction as another vector limited by an angle?

40 Views Asked by At

If I have two 3D vectors as shown by the blue and red vector in the image below, where the red vector is at an angle of more than 20 degrees from the blue vector, how could I calculate a new vector (green in the example) that is exactly 20 degrees away from the blue, in the same direction as the red one? It doesnt need to have the same length as the red one, ideally it would be a unit (normalized direction) vector. How would I do this if the arbitrary angle limit would be a variable named x?

Example Image

1

There are 1 best solutions below

0
On BEST ANSWER

This is really simple. You need to construct a vector that is perpendicular to the blue vector and at the same time in the same plane as both the blue and red vectors, such that the angle between this new vector and the red vector is less than $90^\circ$. This is what is known as Gram-Schmidt orthogonalization. In this case there are only two vectors to orthogonalize. Let the blue vector be $V_1$ and the red vector be $V_2$. Here is what do:

(1) Compute the unit vector along $V_1$, let this vector be $u_1 = \dfrac{V_1}{\| V_1 \| } $

(2) $u_1$ is the first vector in the set of two orthogonal vectors.

(3) Compute the vector $ W = V_2 - (V_2 \cdot u_1) u_1 $

(4) Normalize $W$ and call it $u_2$ , i.e. $u_2 = \dfrac{W}{\| W \| } $

(5) Now the unit vector $v$ that makes exactly $20^\circ$ with $u_1$ in the plane of $u_1$ and $u_2$ is

$ v = \cos(20^\circ) u_1 + \sin(20^\circ) u_2 $