psychopy.tools.mathtools.quatFromAxisAngle

psychopy.tools.mathtools.quatFromAxisAngle(axis, angle, degrees=True, dtype=None)[source]

Create a quaternion to represent a rotation about axis vector by angle.

Parameters:
  • axis (tuple, list, ndarray or str) – Axis vector components or axis name. If a vector, input must be length 3 [x, y, z]. A string can be specified for rotations about world axes (eg. ‘+x’, ‘-z’, ‘+y’, etc.)

  • angle (float) – Rotation angle in radians (or degrees if degrees is True. Rotations are right-handed about the specified axis.

  • degrees (bool, optional) – Indicate angle is in degrees, otherwise angle will be treated as radians.

  • dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. If out is specified, the data type of out is used and this argument is ignored. If out is not provided, ‘float64’ is used by default.

Returns:

Quaternion [x, y, z, w].

Return type:

ndarray

Examples

Create a quaternion from specified axis and angle:

axis = [0., 0., -1.]  # rotate about -Z axis
angle = 90.0  # angle in degrees
ori = quatFromAxisAngle(axis, angle, degrees=True)  # using degrees!

Back to top