Local to global coordinates example

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:

  1. The length of the upper arm is 38 cm;

  2. The shoulder is located 15 cm forward and 70 cm upward from the global origin;

  3. 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:

\[\begin{split} ~^\text{upper arm}p_\text{elbow} = \begin{bmatrix} 0 \\ -0.38 \\ 0 \\ 1 \end{bmatrix} \end{split}\]

The second and third points of information allow us to express the upper arm frame:

\[\begin{split} ~^\text{global}_\text{upper arm}T = \begin{bmatrix} \cos(30) & -\sin(30) & 0 & 0.15 \\ \sin(30) & \cos(30) & 0 & 0.7 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \\= \begin{bmatrix} 0.866 & -0.5 & 0 & 0.15 \\ 0.5 & 0.866 & 0 & 0.7 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \end{split}\]

Therefore, the position of the elbow in the global coordinate system is:

\[ ^\text{global}p_\text{elbow} ~~~= ~~~^\text{global}_\text{upper arm}T ~~~^\text{upper arm}p_\text{elbow} \]
\[\begin{split} ^\text{global}p_\text{elbow} \\= \begin{bmatrix} 0.866 & -0.5 & 0 & 0.15 \\ 0.5 & 0.866 & 0 & 0.7 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 0 \\ -0.38 \\ 0 \\ 1 \end{bmatrix} \\= \begin{bmatrix} 0.34 \\ 0.371 \\ 0 \\ 1 \end{bmatrix} \end{split}\]

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.  ]])