1

Say I have a plane in 3-dimensional space:

An arbitrary plane in 3D space

I have a normal for the face in the form <x,y,z>

I have a rotate function, rotate(x,y,z), which will rotate the plane by an amount in radians on each axis. I want to use this function to apply a rotation that will align the normal with another normal. For simplicity's sake, take an axis vector. Aligning it to the z-axis vector, <0,0,1>, would produce the following result on a Cartesian plane:

Plane in 2D space

Given two 3D vector directions, v1 and v2, how can I derive a set of rotations on each axis to align v1 to v2? I recognize that there are multiple 'ways around' to any given direction in 3D space, but in my case, only the solution is critical.

Similar to Calculate Rotation Matrix to align Vector A to Vector B in 3d?, only I am not using a rotation matrix.

Hackstaar
  • 121
  • 3
  • Do note that I realize the rotated result will not necessarily be aligned nicely like my example. Because of my specific application, performing a second rotation is required anyway. – Hackstaar May 24 '20 at 15:05
  • Are you basically asking how to find the angle between two normals? – amd May 24 '20 at 18:49

1 Answers1

1

Let $v_1 = \big(v_{x,1}, \,v_{y,1}, \, v_{z,1}\big)$ and $v_2 = \big(v_{x,2}, \,v_{y,2}, \, v_{z,2}\big)$. Let $R_z(\theta)$ be the rotation to an angle $\theta$ around axis $z$ counter-clockwise looking from the positive orientation of the $z$ axis. Let $R_y(\psi)$ be the rotation to an angle $\psi$ around axis $y$ counter-clockwise looking from the positive orientation of the $y$ axis. Then the composition of rotations: $$R_{y,z}(v_1) = R_y\left( \, -\,\text{arccot} \left(\frac{v_{z,1}}{\sqrt{v_{x,1}^2 + v_{y,1}^2}}\right)\,\right)\, R_z\left( \,- \,\text{arccot}\left( \frac{v_{x,1}}{v_{y,1}} \right) \,\right)$$ rotates and aligns the vector $v_1$ with the coordinate unit vector $e_z = (0, 0, 1)$. If you want to go from $v_1$ to the vector aligned with $v_2$, simply set up the inverse rotation from $e_z$ to $v_2$: $$R_{y,z}(v_2)^{-1} = R_z\left( \,\text{arccot}\left( \frac{v_{x,2}}{v_{y,2}} \right) \,\right)\,R_y\left( \,\text{arccot} \left(\frac{v_{z,2}}{\sqrt{v_{x,2}^2 + v_{y,2}^2}}\right)\,\right)\, $$

and then the composition $$R_{y,z}(v_2)^{-1} R_{y,z}(v_1) $$ rotates $v_1$ to $v_2$. Have in mind that, depending on which quadrants the vectors $v_1$ and $v_2$ point into, you may or may not need to adjust how you define the function $y=\text{arccot}(x)$. Also, if you want to experiment with alternatives, you could check out the conversion formulas from Cartesian to spherical coordinates. It is related to your question.

Futurologist
  • 9,659