Kinematics (.move)#

Basic functions for movement related data from optical tracking systems. If I have the time I will make a vector3d class. Most functions assume an [n, 3] or [1, 3] array or dataframe.

worklab.move.acs_to_car_ang(acs, order=<class 'list'>)[source]#

Anatomical coordinate system to cardanic angles

Note: Only works if used in the DSEM coordinate system Y pointing upward, X pointing laterally to the right and Z point backwards

Parameters:
  • acs (np.array) – anatomical coordinate system

  • order (list[int]) – list of integers 0=’x’, 1=’y’, 2=’z’

Returns:

angles – cardanic angles

Return type:

np.array

worklab.move.distance(point1, point2)[source]#

Compute Euclidean distance between two points, this is the distance if you were to draw a straight line.

Parameters:
  • point1 (np.array) – a [1, 3] or [n, 3] array with point coordinates

  • point2 (np.array) – a [1, 3] or [n, 3] array with point coordinates

Returns:

distance – distance from point1 to point2 in a [1, 3] or [n, 3] array

Return type:

np.array

worklab.move.find_gh_regression(markers)[source]#

Get the location of the glenohumeral joint in the global coordinate system of DSEM In vivo estimation of the glenohumeral joint rotation center from scapular bony landmarks by linear regression C.G.M. Meskers, F.C.T. van der Helm, L.A. Rozendaal, P.M. Rozing

Parameters:

markers (np.array) – data points of upper-limb kinematics

Returns:

GH – Glenohumeral rotation center in the global coordinate system

Return type:

np.array

worklab.move.flexext_prosup(GH, EL, EM, US, RS)[source]#

Flexion/extension as well as pro/supination in the DSEM reference frame Y pointing upward, X pointing laterally to the right and Z point backwards

Parameters:
  • GH (np.array) – data points of the glenohumeral rotation centre

  • EL (np.array) – data points of the epicondylus lateral

  • EM (np.array) – data points of the epicondylus medial

  • US (np.array) – data points of the ulna styloid

  • RS (np.array) – data points of the radial styloid

Returns:

angles – angles for flexion/extention, as well as pro/supination

Return type:

np.array

worklab.move.get_local_coordinate(marker, acs, origin)[source]#

Make the local coordinate system from the anatomical coordinate system

Parameters:
  • marker (np.array) – marker points

  • acs (np.array) – anatomical coordinate system

  • origin (np.array) – origin for the local coordinate system

Returns:

local_marker – local coordinate system

Return type:

dict[np.array]

worklab.move.get_orthonormal_frame(point1, point2, point3, mean=False)[source]#

Returns an orthonormal frame from three reference points. For example, a local coordinate system from three marker points.

Parameters:
  • point1 (np.array) – first marker point, used as origin if mean=False

  • point2 (np.array) – second marker point, used as x-axis

  • point3 (np.array) – third marker point

  • mean (bool) – using the mean as the origin, default is False

Returns:

  • origin (np.array) – xyz column vector with coordinates of the origin which is point1 or the mean of all points

  • orthonormal (np.array) – 3x3 array with orthonormal coordinates [x, y, z] of the new axis system

worklab.move.get_perp_vector(vector2d, clockwise=True, normalized=True)[source]#

Get the vector perpendicular to the input vector. Only works in 2D as 3D has infinite solutions.

Parameters:
  • vector2d (np.array) – [n, 3] vector data, only uses x and y

  • clockwise (bool) – clockwise or counterclockwise rotation

  • normalized (bool) – normalising the result, default is True

Returns:

perp_vector2d – rotated vector

Return type:

numpy array

worklab.move.get_rotation_matrix(new_frame, local_to_world=True)[source]#

Get the rotation matrix between a new reference frame and the global reference frame or the other way around.

Parameters:
  • new_frame (np.array) – [3, 3] array specifying the new reference frame

  • local_to_world (bool) – global to local or local to global

Returns:

rotation_matrix – rotation matrix that can be used to rotate marker data, e.g.: rotation_matrix @ marker

Return type:

np.array

worklab.move.is_unit_length(vector3d, atol=1e-08)[source]#

Checks whether an array ([1, 3] or [n, 3]) is equal to unit length given a tolerance

worklab.move.magnitude(vector3d)[source]#

Calculates the vector magnitude using a l2 norm. Works with [1, 3] or [n, 3] vectors.

Parameters:

vector3d (np.array) – a [1, 3] or [n, 3] vector

Returns:

vector3d – scalar value or column vector

Return type:

np.array

worklab.move.make_acs_cl(SC, AC, IJ, PX, C7, T8, AA=None, DSEM=False)[source]#

Make the anatomical coordinate system of the clavicle based on ISB recommendations

Y is pointing upwards X is pointing to the front Z is pointing laterally to the right

Parameters:
  • SC (np.array) – data points of the sternoclaviculare joint

  • AC (np.array) – data points of the dorsal acromioclaviculare joint

  • IJ (np.array) – data points of the incisura jugularis

  • PX (np.array) – data points of the processus xiphoideus

  • C7 (np.array) – data points of C7

  • T8 (np.array) – data points of T8

  • AA (np.array) – data points of AA (only necessary for DSEM)

  • DSEM (boolean (default = False)) – set to True to use coordinate system guidelines DSEM Y pointing upward, X pointing laterally to the right and Z point backwards

Returns:

  • local (dict[np.array]) – local coordinate system of the clavicle

  • acs (np.array) – anatomical coordinate system of the clavicle

  • origin (np.array) – origin of the local coordinate system of the clavicle

worklab.move.make_acs_fa(US, RS, EL, EM, DSEM=False)[source]#

Make the anatomical coordinate system of the forearm based on ISB recommendations

Y is pointing upwards X is pointing to the front Z is pointing laterally to the right

Parameters:
  • US (np.array) – data points of the ulna styloid

  • RS (np.array) – data points of the radial styloid

  • EL (np.array) – data points of the epicondylus lateral

  • EM (np.array) – data points of the epicondylus medial

  • DSEM (boolean (default = False)) – set to True to use coordinate system guidelines DSEM Y pointing upward, X pointing laterally to the right and Z point backwards

Returns:

  • local (dict[np.array]) – local coordinate system of the forearm

  • acs (np.array) – anatomical coordinate system of the forearm

  • origin (np.array) – origin of the local coordinate system of the forearm

worklab.move.make_acs_hand(M2, M5, US, RS)[source]#

Make the anatomical coordinate system of the hand in DSEM

Y is pointing upwards X is pointing laterally to the right Z is pointing backwards

Parameters:
  • M2 (np.array) – data points of metacarpal 2

  • M5 (np.array) – data points of metacarpal 5

  • US (np.array) – data points of the ulna styloid

  • RS (np.array) – data points of the radial styloid

Returns:

  • local (dict[np.array]) – local coordinate system of the hand

  • acs (np.array) – anatomical coordinate system of the hand

  • origin (np.array) – origin of the local coordinate system of the hand

worklab.move.make_acs_hu(GH, EL, EM, DSEM=False)[source]#

Make the anatomical coordinate system of the humerus based on ISB recommendations

Y is pointing upwards X is pointing to the front Z is pointing laterally to the right

Parameters:
  • GH (np.array) – data points of the glenohumeral rotation centre

  • EL (np.array) – data points of the epicondylus lateral

  • EM (np.array) – data points of the epicondylus medial

  • DSEM (boolean (default = False)) – set to True to use coordinate system guidelines DSEM Y pointing upward, X pointing laterally to the right and Z point backwards

Returns:

  • local (dict[np.array]) – local coordinate system of the humerus

  • acs (np.array) – anatomical coordinate system of the humerus

  • origin (np.array) – origin of the local coordinate system of the humerus

worklab.move.make_acs_sc(AA, TS, AI, DSEM=False)[source]#

Make the anatomical coordinate system of the scapula based on ISB recommendations

Y is pointing upwards X is pointing to the front Z is pointing laterally to the right

Parameters:
  • AA (np.array) – data points of the angulus acromialis

  • TS (np.array) – data points of the trigonum spinae

  • AI (np.array) – data points of the angulus inferior

  • DSEM (boolean) – set to True to use coordinate system guidelines DSEM Y pointing upward, X pointing laterally to the right and Z point backwards

Returns:

  • local (dict[np.array]) – local coordinate system of the scapula

  • acs (np.array) – anatomical coordinate system of the scapula

  • origin (np.array) – origin of the local coordinate system of the scapula

worklab.move.make_acs_th(IJ, PX, C7, T8, DSEM=False)[source]#

Make the anatomical coordinate system of the thorax based on ISB recommendations

Y is pointing upwards X is pointing to the front Z is pointing laterally to the right

Parameters:
  • IJ (np.array) – data points of the incisura jugularis

  • PX (np.array) – data points of the processus xiphoideus

  • C7 (np.array) – data points of C7

  • T8 (np.array) – data points of T8

  • DSEM (boolean (default = False)) – set to True to use coordinate system guidelines DSEM Y pointing upward, X pointing laterally to the right and Z point backwards

Returns:

  • local (dict[np.array]) – local coordinate system of the thorax

  • acs (np.array) – anatomical coordinate system of the thorax

  • origin (np.array) – origin of the local coordinate system of the thorax

worklab.move.make_marker_dict(markers, marker_names=None)[source]#

Create a dictionary of nx3 arrays with name samples

Parameters:
  • markers (np.array) – marker points

  • marker_names (list[strings]) – list of marker names

Returns:

marker_dict – dictionary of nx3 markers with names

Return type:

dict[np.array]

worklab.move.marker_angles(v_1, v_2, deg=False)[source]#

Calculates n angles between two [n, 3] markers, two [1, 3] markers, or one [n, 3] and one [1, 3] marker.

Parameters:
  • v_1 (np.array) – [n, 3] array or DataFrame for marker 1

  • v_2 (np.array) – [n, 3] array or DataFrame for marker 2

  • deg (bool) – return radians or degrees, default is radians

Returns:

x – returns [n, 1] array with the angle for each sample or scalar value

Return type:

np.array

worklab.move.mirror(vector3d, axis='xyz')[source]#

Simply mirror one or multiple axes.

Parameters:
  • vector3d (np.array) – vector to be mirrored, also works on dataframes

  • axis (str) – string with axes to be mirrored

Returns:

vector3d – mirrored vector

Return type:

np.array

worklab.move.normalize(vector3d)[source]#

Normalizes [n, 3] marker data using a l2 norm. Works with [1, 3] and [n, 3] vectors, both arrays and dataframes.

Parameters:

vector3d (np.array) – marker data to be normalized

Returns:

vector3d – normalized marker data

Return type:

np.array

worklab.move.rotate(vector3d, angle, deg=False, axis='z')[source]#

Rotate a vector around a single given axis, specify rotation angle in radians or degrees.

Parameters:
  • vector3d (np.array) – vector to be rotated, also works on dataframes, assumes [n, xyz] data

  • angle (float) – angle to rotate over

  • deg (bool) – True if angle is specified in degrees, False for radians

  • axis (str) – axis to rotate over, default = “z”

Returns:

vector3d – rotated vector

Return type:

np.array

worklab.move.rotate_matrix(ang, axis='z')[source]#

Create a rotation matrix to rotate around x, y or z-axis

Parameters:
  • ang (int) – angle of rotation

  • axis (string (default = 'z')) – axis of rotation, ‘x’, ‘y’ or ‘z’

Returns:

rotate – rotation matrix

Return type:

np.array

worklab.move.scale(vector3d, x=1.0, y=1.0, z=1.0)[source]#

Scale a vector in different directions.

Parameters:
  • vector3d (np.array) – array to be scaled, also works on dataframes, assumes [n, xyz] data

  • x (float) – x-axis scaling

  • y (float) – y-axis scaling

  • z (float) – z-axis scaling

Returns:

vector3d – scaled array

Return type:

np.array