9.2.1. Moving points#
Let 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.7.
We first express the original coordinates of the point:
We then express the rotation and translation that we want to apply to this point:
We multiply the position to the transform to obtain the final position of the point:
The final coordinates of the points are (10.66, 5, 0).
9.2.1.1. Application in Kinetics Toolkit#
We can do the same in Kinetics Toolkit, using the function ktk.geometry.create_transforms that creates series of homogeneous transforms based on angles and translations. For instance, the transform \(T\) used in this section 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],
translations=[[2, 0, 0]],
degrees=True,
)
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 translations
values are enclosed in bracket. Similarly, the return transformed \(T\) is also enclosed in an additional first dimension. This is because all functions in the ktk.geometry module work on series of data, and the first dimensions is always reserved to 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.2.1.2. Direct transformation in Kinetics Toolkit#
Kinetics Toolkit’s geometry module also provides simpler function to provide 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 we can use these simpler 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. ]])