Skip to content

pymath.quat_from_matrix

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

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

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

q = pymath.quat_from_matrix(mat)
Parameter Type Description
mat matrix A 3×3 rotation matrix, represented as an array of three row-vectors. Missing or non-numeric entries are read as 0.

Return value

Type Description
q A new unit quaternion {x, y, z, w} describing the same rotation as mat.

Notes:

  • mat is expected to be a proper rotation matrix (orthogonal, determinant +1).
  • The inverse operation is pymath.matrix_from_quat.

Example:

local R = pymath.matrix_from_quat({0, 0, 0.70710678, 0.70710678})
local q = pymath.quat_from_matrix(R)
-- q == {0, 0, 0.70710678, 0.70710678}   (round-trip)

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.matrix_from_quat, pymath.quat_from_rotation

Clone this wiki locally