Rotate vector by a random little amount

309 Views Asked by At

Suppose there is a vector $v = (v_x, v_y, v_z)$.

I want to rotate this vector by a random little amount (let's say at most $10º$). How can I do that?

For better visualization, suppose $v$ begins in the middle of a sphere and I want to move $v$'s end to any point of the red circle.

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Find two mutually perpendicular unit vectors $u_1$ and $u_2$ that are also perpendicular to your vector $v$

Thus the vectors $u_1, u_2, \dfrac{v}{\| v \|} $ form an orthonormal basis for $\mathbb{R}^3$. Let the rotation matrix $R$ be defined as follows:

$R = \left[ u_1, u_2, \dfrac{v}{\| v\| } \right]$

Then vectors $x$ in $\mathbb{R}^3$ are expressed in this basis as $y$ as follows

$x = R y $

Note that the $y$ corresponding to your vector $v$ is

$ y = \begin{bmatrix} 0 \\ 0 \\ \|v\| \end{bmatrix}$

Now using spherical coordinates, we can express your desired vector as

$ y =r \begin{bmatrix} \sin \theta \cos \phi \\ \sin \theta \sin \phi \\ \cos \theta \end{bmatrix} $

where from the conditions of the problem $0 \le \theta \le 10^\circ $ and $\phi$ is arbitrary. And $r=\|v\|$.

And finally the new vector in the world coordinates is given by

$ x = R y $