Exercise: Moving a trajectory

9.2.3.4. Exercise: Moving a trajectory#

The trajectory of a point in global coordinates is:

\[\begin{split} \vec{p}(t_0) = (3, 4, 5) \\ \vec{p}(t_1) = (4, 5, 5) \\ \vec{p}(t_2) = (5, 6, 5) \\ \vec{p}(t_3) = (6, 7, 5) \\ \vec{p}(t_4) = (7, 8, 5) \\ \end{split}\]

Using Kinetics Toolkit’s geometry module, rotate this whole trajectory anti-clockwise on the z axis 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(
    [
        [3.0, 4.0, 5.0, 1.0],
        [4.0, 5.0, 5.0, 1.0],
        [5.0, 6.0, 5.0, 1.0],
        [6.0, 7.0, 5.0, 1.0],
        [7.0, 8.0, 5.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.45099729, 4.78483091, 5.        , 1.        ],
       [1.04866977, 6.06654368, 5.        , 1.        ],
       [1.64634224, 7.34825644, 5.        , 1.        ],
       [2.24401472, 8.62996921, 5.        , 1.        ],
       [2.8416872 , 9.91168197, 5.        , 1.        ]])

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

Hide code cell content
p = np.array(
    [
        [3.0, 4.0, 5.0, 1.0],
        [4.0, 5.0, 5.0, 1.0],
        [5.0, 6.0, 5.0, 1.0],
        [6.0, 7.0, 5.0, 1.0],
        [7.0, 8.0, 5.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.45099729, 4.78483091, 5.        , 1.        ],
       [1.04866977, 6.06654368, 5.        , 1.        ],
       [1.64634224, 7.34825644, 5.        , 1.        ],
       [2.24401472, 8.62996921, 5.        , 1.        ],
       [2.8416872 , 9.91168197, 5.        , 1.        ]])