Exercise: Moving a point

9.2.3.3. Exercise: Moving a point#

The global coordinates of a point are:

\[ \vec{p} = (1, 2, 0) \]

Using Kinetics Toolkit’s geometry module, rotate this point anti-clockwise by 20° then translate it by one unit to the left.

a) Do this exercise by creating the corresponding homogeneous transform using ktk.geometry.create_transforms, then by multiplying this transform by the point coordinates using ktk.geometry.matmul.

Hide code cell content
import kineticstoolkit.lab as ktk
import numpy as np


p = np.array([[1.0, 2.0, 0.0, 1.0]])
T = ktk.geometry.create_transforms(
    angles=[np.deg2rad(20)], seq="z", translations=[[-1.0, 0.0, 0.0]]
)

ktk.geometry.matmul(T, p)
array([[-0.74434767,  2.22140538,  0.        ,  1.        ]])

b) Do this exercise using the ktk.geometry.rotate and ktk.geometry.translate function.

Hide code cell content
p = np.array([[1.0, 2.0, 0.0, 1.0]])

rotated_p = ktk.geometry.rotate(p, angles=[np.deg2rad(20)], seq="z")
final_p = ktk.geometry.translate(rotated_p, translations=[[-1.0, 0.0, 0.0]])

final_p
array([[-0.74434767,  2.22140538,  0.        ,  1.        ]])