9.2.2. Rotating vectors#

For this second example, let’s apply this same transform to a vector of 10 units toward de x axis (10, 0, 0) as shown in Fig. 9.8.

Fig. 9.8 Rotating a vector in respect to the global reference frame.#

The same equation applies:

\[ ^\text{global} \vec{v}_{\text{tranformed}} ~~~ = ~~~ T ~~~ ^\text{global} \vec{v}_\text{initial} \]

Although vector \(\vec{v}_\text{initial}\) shares the same coordinates as \(p_\text{initial}\) in the previous example, its written differently (with a 0 instead of a 1 on the fourth coordinate). This is because the fourth element is responsible for translations, and contrarily to a point, a vector cannot be translated.

\[\begin{split} ^\text{global} \vec{v}_\text{initial} = \begin{bmatrix} 10 \\ 0 \\ 0 \\ 0 \end{bmatrix} \end{split}\]

We multiply this vector by the transform to obtain the final vector:

\[\begin{split} ^\text{global} \vec{v}_{\text{tranformed}} = \begin{bmatrix} \cos(30) & -\sin(30) & 0 & 2 \\ \sin(30) & \cos(30) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 10 \\ 0 \\ 0 \\ 0 \end{bmatrix} \\ = \begin{bmatrix} 10\cos(30) \\ 10\sin(30) \\ 0 \\ 0 \end{bmatrix} = \begin{bmatrix} 8.66 \\ 5 \\ 0 \\ 0 \end{bmatrix} \end{split}\]

The final coordinates of the vector are (8.66, 5, 0).

9.2.2.1. Application in Kinetics Toolkit#

The transform \(T\) can be created using:

import kineticstoolkit.lab as ktk

T = ktk.geometry.create_transforms(
    seq="z",  # Which means a rotation around the z axis
    angles=[30],
    degrees=True,
)

T
array([[[ 0.8660254, -0.5      ,  0.       ,  0.       ],
        [ 0.5      ,  0.8660254,  0.       ,  0.       ],
        [ 0.       ,  0.       ,  1.       ,  0.       ],
        [ 0.       ,  0.       ,  0.       ,  1.       ]]])

The rotated vector is:

ktk.geometry.matmul(T, [[10, 0, 0, 1]])
array([[8.66025404, 5.        , 0.        , 1.        ]])

9.2.2.2. Direct transformation in Kinetics Toolkit#

We can also rotate the vector directly using ktk.geometry.rotate:

ktk.geometry.rotate([[10, 0, 0, 0]], seq="z", angles=[30], degrees=True)
array([[8.66025404, 5.        , 0.        , 0.        ]])