Skip to content

pymath.matrix_from_quat

Daniel Flassig edited this page Jun 24, 2026 · 1 revision

Computes the 3×3 rotation matrix corresponding to a quaternion.

This function is located in the pymath module. See pymath for the quaternion and matrix representations.

mat = pymath.matrix_from_quat(q)
Parameter Type Description
q quaternion A quaternion {x, y, z, w}. It is normalized internally if necessary, so it need not be a unit quaternion.

Return value

Type Description
mat A new 3×3 rotation matrix, represented as an array of three row-vectors.

Notes:

  • q is normalized first, so a non-unit quaternion still yields a proper rotation matrix.
  • The inverse operation is pymath.quat_from_matrix.

Example:

-- 90° rotation about the z-axis
local R = pymath.matrix_from_quat({0, 0, 0.70710678, 0.70710678})
-- R == {{0, -1, 0},
--       {1,  0, 0},
--       {0,  0, 1}}

-- Apply it to a vector with pymath.dot:
local v = pymath.dot(R, {1, 0, 0})
-- v == {0, 1, 0}

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.quat_from_matrix, pymath.rotate_by_quat, pymath.dot

Clone this wiki locally