, degrees=True, dtype=None)[source]

Convert a quaternion to axis and angle representation.

This allows you to use quaternions to set the orientation of stimuli that have an ori property.

  • q (tuple, list or ndarray of float) – Quaternion in form [x, y, z, w] where w is real and x, y, z are imaginary components.

  • degrees (bool, optional) – Indicate angle is to be returned in degrees, otherwise angle will be returned in 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.


Axis and angle of quaternion in form ([ax, ay, az], angle). If degrees is True, the angle returned is in degrees, radians if False.

Return type



Using a quaternion to rotate a stimulus a fixed angle each frame:

# initial orientation, axis rotates in the Z direction
qr = quatFromAxisAngle([0., 0., -1.], 0.0, degrees=True)
# rotation per-frame, here it's 0.1 degrees per frame
qf = quatFromAxisAngle([0., 0., -1.], 0.1, degrees=True)

# ---- within main experiment loop ----
# myStim is a GratingStim or anything with an 'ori' argument which
# accepts angle in degrees
qr = multQuat(qr, qf)  # cumulative rotation
_, angle = quatToAxisAngle(qr)  # discard axis, only need angle
myStim.ori = angle

Back to top