9.4.3. Local to global coordinates example#
This ability to switch between coordinate systems is very powerful. Let’s get back to Fig. 9.4.
Using this information:
The length of the upper arm is 38 cm;
The shoulder is located 15 cm forward and 70 cm upward from the global origin;
The upper arm is inclined at 30 degrees to the vertical.
We want to know the position of the elbow in global coordinates.
Solution:
The first piece of information allows us to express the position of the elbow in the local upper arm coordinate system:
The second and third points of information allow us to express the upper arm frame:
Therefore, the position of the elbow in the global coordinate system is:
Its global coordinates are \((0.34, 0.371, 0)\).
9.4.3.1. Changing coordinate systems using Kinetics Toolkit#
Using the ktk.geometry.create_transform_series and ktk.geometry.matmul functions introduced in the previous section, we can solve this problem as follows:
import kineticstoolkit.lab as ktk
T_upperarm = ktk.geometry.create_transform_series(
angles=[30], degrees=True, seq="z", positions=[[0.15, 0.7, 0]],
)
local_p_elbow = [[0, -0.38, 0, 1]]
global_p_elbow = ktk.geometry.matmul(T_upperarm, local_p_elbow)
global_p_elbow
array([[0.34 , 0.37091035, 0. , 1. ]])
However, since changing coordinates between reference frames is so common, Kinetics Toolkit also provides the functions ktk.geometry.get_global_coordinates and ktk.geometry.get_local_coordinates. These functions are simple shortcuts but are easier to remember:
global_p_elbow = ktk.geometry.get_global_coordinates(
local_coordinates=local_p_elbow, reference_frames=T_upperarm
)
global_p_elbow
array([[0.34 , 0.37091035, 0. , 1. ]])
local_p_elbow = ktk.geometry.get_local_coordinates(
global_coordinates=global_p_elbow, reference_frames=T_upperarm
)
local_p_elbow
array([[ 0. , -0.38, 0. , 1. ]])