# How to perform multiple rotations by direction vectors?

I am looking for some performant algorithm for a rotation of multiple points in $$\mathbb{R}^2$$ (and maybe also $$\mathbb{R}^3$$ with one coordinate zero) around the origin.

Full story: I want to draw a texture on a quad plane along some line, rotated to the direction of the line. I know how to perform the translation beside the rotation.

If you already know the angle, you can build a rotation matrix or a quaternion/complex number using that for each point.

However, what I need is just a transformation between two direction vectors in the special case where the source direction is up $$\vec{s}=\pmatrix{0\\1}$$. The destination direction can be arbitrary and the vector does not necessarily have to be normalized ($$\lvert\vec{d}\rvert \not=1$$).

Can it be done by getting the normalized unit vector $$\vec{u_d} = \frac{\vec{d}}{\lvert\vec{d}\rvert} = \frac{\pmatrix{x\\y}}{\sqrt{x^2+y^2}}$$ and just using the coordinates as $$\sin$$ / $$\cos$$ in a rotation matrix?

Since the source direction is up instead of along the x-axis, I guess $$-\sin = x$$ ; $$cos = y$$ of the normalized destination vector.

Would the thoughts above work? Is there any more performant way to do a rotation directly avoiding both, square root and sin/cos (e.g. using complex numbers or quaternions)? How else would I achieve what I want?

• I'm neither a math pro nor a native English speaker. Math language differs between countries. Please feel free to edit my question to transform it into a fluent English math language. Jun 14, 2022 at 0:08
• Your way seems about as simple and efficient as you can get. You might need to try swapping $x$ and $-x$ to get it to work correctly. Jun 15, 2022 at 12:55

As you proposed, you can use a rotation matrix $$R_\theta=\left[\matrix{\cos(\theta)& -\sin(\theta)\\ \sin(\theta)& cos(\theta)}\right]$$.
If you have uv coordinates $$\vec{s}_1$$ and $$\vec{s}_2$$ in the ordinary base $$B=\left[\matrix{1 & 0\\ 0 & 1}\right]$$ to rotate them you need to multiply them by $$R_\theta$$. If they concide with the base, it will result in $$R_\theta$$: $$R_\theta B=R_\theta,$$ meaning your rotated $${\vec{s}_1}^\theta$$ and $${\vec{s}_2}^\theta$$ will be $${\vec{s}_1}^\theta=\left[\matrix{\cos(\theta)\\ \sin(\theta)}\right]$$ and $${\vec{s}_2}^\theta=\left[\matrix{-\sin(\theta)\\ \cos(\theta)}\right].$$