How to find rotation quaternion for a model so that it is perpendicular to a line in 3D space?

1.1k Views Asked by At

How to find the target rotation quaternion for a model when one of its faces need to be aligned perpendicular to a line in 3D space. For example, if the model is a cube and if two 3D points connecting a straight line in 3D space are known, the question is how to find the quaternion to be applied to the cube so that one of the cube's faces is parallel to a plane that is perpendicular to the line connecting the two points. It is known that quaternion has 4 components namely $x$, $y$, $z$, $w$. Since perpendicular is $90$ degree, one of the quaternion components (say $y$ component) will be set to $90$ degree (if I'm correct), but still values for other axes (say $x$ and $z$ components of quaternion) need to be found. Wondering whether I'm missing something basic here!

1

There are 1 best solutions below

0
On

This is the same as finding the rotation of a unit vector, from the initial normal to the given normal. Suppose they are given by $v_0$ and $v_1$, the rotation axis is given by $\omega=(v_0\times v_1)/\|v_0\times v_1\|$, and the rotation angle is given by $\theta=\arcsin(\|v_0\times v_1\|)$, and the corresponding quaternion is given by: $$ \cos\theta/2+\omega\sin\theta/2=(\underbrace{\cos\theta/2}_{w},\underbrace{\omega_1\sin\theta/2}_{x},\underbrace{\omega_2\sin\theta/2}_{y},\underbrace{\omega_3\sin\theta/2}_{z}) $$