matrix_from_quaternion

compas.geometry.matrix_from_quaternion(quaternion)[source]

Calculates a rotation matrix from quaternion coefficients.

Parameters

quaternion (list of float) – Four numbers that represents the four coefficient values of a quaternion.

Returns

list of list of float – The 4x4 transformation matrix representing a rotation.

Raises

ValueError – If quaternion is invalid.

Examples

>>> q1 = [0.945, -0.021, -0.125, 0.303]
>>> R = matrix_from_quaternion(q1)
>>> q2 = quaternion_from_matrix(R)
>>> allclose(q1, q2, tol=1e-03)
True