ktk.geometry.rotate#

rotate(coordinates, /, seq, angles, *, degrees=False)[source]#

Rotate a series of coordinates along given axes.

Parameters
  • coordinates – Array_like of shape (N, …): the coordinates to rotate.

  • seq (str) – Specifies sequence of axes for rotations. Up to 3 characters belonging to the set {“X”, “Y”, “Z”} for intrinsic rotations (moving axes), or {“x”, “y”, “z”} for extrinsic rotations (fixed axes). Extrinsic and intrinsic rotations cannot be mixed in one function call.

  • angles (ArrayLike) –

    Array_like of shape (N,) or (N, [1 or 2 or 3]). Angles are specified in radians (if degrees is False) or degrees (if degrees is True).

    For a single-character seq, angles can be:

    • array_like with shape (N,), where each angle[i] corresponds to a single rotation;

    • array_like with shape (N, 1), where each angle[i, 0] corresponds to a single rotation.

    For 2- and 3-character seq, angles is an array_like with shape (N, W) where each angle[i, :] corresponds to a sequence of Euler angles and W is the length of seq.

  • degrees (bool) – If True, then the given angles are in degrees. Default is False.

Returns

Array_like of shape (N, …): the rotated coordinates.

Return type

np.ndarray

Examples

Rotate the point (1, 0, 0) by theta degrees around z, then by 45 degrees around y, for theta in [0, 10, 20, 30, 40]:

>>> import kineticstoolkit.lab as ktk
>>> angles = np.array([[0, 45], [10, 45], [20, 45], [30, 45], [40, 45]])
>>> ktk.geometry.rotate([[1, 0, 0, 1]], "zx", angles, degrees=True)
array([[1.        , 0.        , 0.        , 1.        ],
       [0.98480775, 0.1227878 , 0.1227878 , 1.        ],
       [0.93969262, 0.24184476, 0.24184476, 1.        ],
       [0.8660254 , 0.35355339, 0.35355339, 1.        ],
       [0.76604444, 0.45451948, 0.45451948, 1.        ]])