9.3.1. Moving points#

Let’s say we want to rotate the point located at (10, 0, 0) by 30 degrees around the origin’s z-axis, then translate it 2 units to the right as shown in Fig. 9.10.

Fig. 9.10 Rotating and translating a point in respect to the global reference frame.#

We first express the original coordinates of the point:

\[\begin{split} ^\text{global} p_\text{initial} = \begin{bmatrix} 10 \\ 0 \\ 0 \\ 1 \end{bmatrix} \end{split}\]

We then express the rotation and translation that we want to apply to this point:

\[\begin{split} T = \begin{bmatrix} \cos(30) & -\sin(30) & 0 & 2 \\ \sin(30) & \cos(30) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \end{split}\]

We multiply the position by the transform to obtain the final position of the point:

\[\begin{split} ^\text{global} p_{\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 \\ 1 \end{bmatrix} \\ = \begin{bmatrix} 10\cos(30) + 2 \\ 10\sin(30) \\ 0 \\ 1 \end{bmatrix} = \begin{bmatrix} 10.66 \\ 5 \\ 0 \\ 1 \end{bmatrix} \end{split}\]

The final coordinates of the point are (10.66, 5, 0).

9.3.1.1. Application in Kinetics Toolkit#

We can do the same in Kinetics Toolkit, using the function ktk.geometry.create_transform_series. The transform \(T\) used in this section is created using:

import kineticstoolkit.lab as ktk

T = ktk.geometry.create_transform_series(
    angles=[30],
    degrees=True,
    seq="z",  # Which means a rotation around the z axis
    positions=[[2, 0, 0, 1]],  # 4th column
)

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

Caution

Note that the angles and positions values are enclosed in brackets. This is because all functions in the ktk.geometry module work on series of data, and the first dimension is always reserved for time. Please consult this section for more information.

The function ktk.geometry.matmul performs matrix multiplications on data series. It can therefore be used to obtain the solution to the previous examples.

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

9.3.1.2. Direct transformation in Kinetics Toolkit#

Kinetics Toolkit’s geometry module also provides simpler functions to perform basic geometry operations, such as ktk.geometry.rotate, ktk.geometry.translate, and ktk.geometry.scale. If we don’t need to express a full homogeneous transform, then it is generally simpler to use these functions:

point = [[10, 0, 0, 1]]
rotated_point = ktk.geometry.rotate(point, seq="z", angles=[30], degrees=True)
final_point = ktk.geometry.translate(rotated_point, translations=[[2, 0, 0]])

final_point
array([[10.66025404,  5.        ,  0.        ,  1.        ]])