Cardinal Rotation II

In part I, we introduced the concept of a cardinal vector. A slight refinement is necessary before we can implement it in code.

A single cardinal vector is a sufficient description of a rotation in 2D but not in 3D. This is because in 3D, two rotations can be “facing” the same direction but have different orientations. Therefore, our rotation object must differentiate between unique orientations.

To accomodate this, we will store the “forward” direction (i.e. cardinal vector) and an upwards direction in our rotation object. For completeness, we will store “forward”, “upwards”, and “right”.


Nomenclature

Sign Domain Math

Since the sign domain $ \mathbb{S} $ is a (proper) subset of the integers $ \mathbb{Z} $, addition and multiplication between elements in $ \mathbb{S} $ are (already) defined. $$ (\forall a, b \in \mathbb{S})(\exists x \in \mathbb{Z} \mid x = a + b) \tag{Theorem 2.2} $$ $$ (\forall a, b \in \mathbb{S})(\exists x \in \mathbb{S} \mid x = a \cdot b) \tag{Theorem 2.1} $$

Notice that $ \mathbb{S} $ is not closed under addition, but is closed under multiplication.

Sign Domain Dot Product

Let’s define sign domain dot product for cardinal vectors in $ \mathbb{S} ^ N $: $$ \vec{a} \cdot \vec{b} = \displaystyle\sum_{i=1}^N \vec{a}_i \cdot \vec{b}_i \tag{Definition 2.3} $$ where $$ \vec{a}, \vec{b} \in \mathbb{S} ^ N $$


Theory

Let $ \vec{d} $ represent some arbitrary cardinal vector in $ \mathbb{S}^3 $. If $ \vec{d} $ acts as our “forward”, then define cardinal vectors $ \vec{m_0} $, $ \vec{m_1} $, and $ \vec{m_2} $ such that

$$ \vec{m_2} = \vec{d} \tag{1} $$

$$ \vec{m_0} \cdot \vec{m_1} = \vec{m_1} \cdot \vec{m_2} = \vec{m_2} \cdot \vec{m_0} = 0 \tag{2} $$ where

$$ \vec{m_0}, \vec{m_1}, \vec{m_2} \in \mathbb{S} ^ N $$

That is $ \vec{m_2} $ assumes the direction given by $ \vec{d} $ (Condition 1) and all vectors $ \vec{m_0} $, $ \vec{m_1} $, and $ \vec{m_2} $ are linearly independent (Condition 2). In esssence, these vectors form an orthonormal basis for $ \mathbb{S} ^ 3 $ specified by $ \vec{d} $.

We are free to choose any $ \vec{m_0} $ and $ \vec{m_1} $ as long as the conditions above remain satisfied.

With $ N = 3 $ vectors (each with $ N = 3 $ components) we encode them into the $ 3 \times 3 $ cardinal matrix $ M $.

$$ \boxed{ M = \begin{bmatrix} \vert & \vert & \vert \\ \vec{m_0} & \vec{m_1} & \vec{m_2} \\ \vert & \vert & \vert \end{bmatrix} \tag{Definition 2.4} } $$

where

$$ M \in \mathbb{S} ^ {N \times N} $$


How are $ \vec{m_0} $ and $ \vec{m_2} $ obtained?

We obtain these the same way Unity does with Quaternions: given some direction $ \vec{d} $, start with $ \vec{d} $ and perform two cross products to infer the entire basis.

Let $$ \vec{m_2} = \vec{d} $$ Compute the cross product of $ \vec{m_2} $ and some reference vector $ \vec{w} $. By default, Unity uses $ \hat{j} = \langle 0, 1, 0 \rangle $ for $ \vec{w} $.

If $ \vec{m_2} $ is collinear with $ \hat{j} $, the cross product will produce an invalid result. To fix this, Unity fallbacks to the “right” basis vector $ \hat{i} = \langle 1, 0, 0 \rangle $ for $ \vec{w} $.

$$ \vec{m_0} = \vec{w} \times \vec{m_2} $$

Finally, compute the cross product of $ \vec{m_2} $ of and $ \vec{m_0} $ to obtain $ \vec{m_1} $. $$ \vec{m_1} = \vec{m_2} \times \vec{m_0} $$

Warning: the sign domain $ \mathbb{S} $ is not closed under vector cross product!


Example 2.3

Let’s examine how a cardinal matrix can transform a vector. Suppose $ \vec{d} = \langle -1, 0, 0 \rangle $. One possible cardinal matrix $ M $ for $ \vec{d} $ is $$ M = \begin{bmatrix} 0 & 0 & -1 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \end{bmatrix} $$

The keen reader will recognize that $ M $ represents a counter-clockwise rotation around the Y-axis by 90° (using left-hand rules).

Consider the vector $ \vec{s} = \langle 10, 20, 30 \rangle $ where $ \vec{s} \in \mathbb{Z} ^ 3 $. We can transform $ \vec{s} $ by $ M $ using ordinary matrix multiplication of a matrix and vector.

$$ \begin{aligned} \vec{t} &= M \cdot \vec{s} \\ &= \begin{bmatrix} \vert & \vert & \vert \\ \vec{m_0} & \vec{m_1} & \vec{m_2} \\ \vert & \vert & \vert \end{bmatrix} \cdot \begin{bmatrix} \vert \\ \vec{s} \\ \vert \end{bmatrix} \\ &= \begin{bmatrix} \vec{m_0}_x & \vec{m_1}_x & \vec{m_2}_x \\ \vec{m_0}_y & \vec{m_1}_y & \vec{m_2}_y \\ \vec{m_0}_z & \vec{m_1}_z & \vec{m_2}_z \end{bmatrix} \cdot \begin{bmatrix} \vec{s}_x \\ \vec{s}_y \\ \vec{s}_z \end{bmatrix} \\ &= \begin{bmatrix} 0 & 0 & -1 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \end {bmatrix} \cdot \begin{bmatrix} 10 \\ 20 \\ 30 \end{bmatrix} \\ &= \begin{bmatrix} 0 \cdot 10 + 0 \cdot 20 + -1 \cdot 30 \\ 0 \cdot 10 + 1 \cdot 20 + 0 \cdot 30 \\ 1 \cdot 10 + 0 \cdot 20 + 0 \cdot 30 \end{bmatrix} \\ &= \begin{bmatrix} 0 + 0 + -30 \\ 0 + 20 + 0 \\ 10 + 0 + 0 \end{bmatrix} \\ &= \boxed{ \begin{bmatrix} -30 \\ 20 \\ 10 \end{bmatrix} } \end{aligned} $$

Example 2.4

Let’s show how to combine two cardinal matricies by chaining them.

Let $ A = \begin{bmatrix} 0 & 0 & -1 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \end{bmatrix} $ and $ B = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{bmatrix} $

Here, $ A $ represents a counter-clockwise rotation around the Y-axis by 90°. $ B $ represents a clockwise rotation around the X-axis by 90°.

Multiply $ A $ and $ B $ using matrix multiplication to obtain $ C $.

$$ \begin{aligned} C &= A \cdot B \\ &= \begin{bmatrix} 0 & 0 & -1 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{bmatrix} \\ &= \begin{bmatrix} 0 \cdot 1 + 0 \cdot 0 + -1 \cdot 0 & 0 \cdot 0 + 0 \cdot 0 + -1 \cdot 1 & 0 \cdot 0 + 0 \cdot -1 + -1 \cdot 0 \\ 0 \cdot 1 + 1 \cdot 0 + 0 \cdot 0 & 0 \cdot 0 + 1 \cdot 0 + 0 \cdot 1 & 0 \cdot 0 + 1 \cdot -1 + 0 \cdot 0 \\ 1 \cdot 1 + 0 \cdot 0 + 0 \cdot 0 & 1 \cdot 0 + 0 \cdot 0 + 0 \cdot 1 & 1 \cdot 0 + 0 \cdot -1 + 0 \cdot 0 \end{bmatrix} \\ &= \begin{bmatrix} 0 + 0 + 0 & 0 + 0 + -1 & 0 + 0 + 0 \\ 0 + 0 + 0 & 0 + 0 + 0 & 0 + -1 + 0 \\ 1 + 0 + 0 & 0 + 0 + 0 & 0 + 0 + 0 \end{bmatrix} \\ &= \boxed{ \begin{bmatrix} 0 & -1 & 0 \\ 0 & 0 & -1 \\ 1 & 0 & 0 \end{bmatrix} } \end{aligned} $$

Conclusion

The cardinal matrix offers a solution to storing and manipulating rotations. Next time, we implement the rotation object in code.


1245 Words

2021-02-08 01:25 +0000