I'm making a 3d game and I'm running into some mathematical calcualtions that are eluding me.
I have a door with a 3d quaternion rotation and I have a reference point located so many units away on the line perpendicular to the door, and so many units away on the line parallel to the door. How can I calculate the unrotated x, y coordinates relative to the door (using the door as the center of the coordinate system)?
Thanks all...
I would rotate the unit basis vectors $i=(1, 0, 0)^\top$, $j=(0, 1, 0)^\top$ and $k=(0, 0, 1)^\top$ to get the basis vectors of your "door" coordinate frame. To find your x-y points, just scale these new unit basis vectors by how far away you need to go.
I'll use the following notation:
I believe all you need is to find $i_D$ and $j_D$. Just rotate $i_W$ and $j_W$ to get them.
There are two ways to do this: The most common is to convert your vector to a quaternion by just adding a 0 for the scalar part (sometimes called the $w$ term) and performing:
$$ \begin{bmatrix} 0\\ i_D\end{bmatrix} = q_I^D \otimes \begin{bmatrix} 0 \\ i_W \end{bmatrix} \otimes q_I^{D,-1} $$
However, there is actually a more efficient way I ran into a while back: molecular musings
t = 2 * cross(q.xyz, v)v' = v + q.w * t + cross(q.xyz, t)I have used this to great effect.
One thing to be really careful about is the direction of your quaternion. In engineering, a quaternion is usually defined as "passive". This means it relates two coordinate frames - i.e. "rotating" a vector by a quaternion results in the same vector object, described in the new frame. An active rotation results in a new, rotated object described in the original frame.
This is why sometimes rotating a quaternion vectors with quaternions result in the opposite of what you might intuitively expect if you are unclear on what kind of quaternion you have. Luckily, passive and active rotations are the inverse of one another (just flip the sign of the $w$ term). I would play with some known rotations to convince yourself that you have the right quaternion. Once you have that, quaternions aren't too bad, and much more efficient than using trigonometry.