Skip to content

pymath.quat_from_rotation

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

Builds the unit quaternion that represents a rotation by angle about axis.

This function is located in the pymath module. See pymath for the quaternion representation.

q = pymath.quat_from_rotation(axis, angle)
Parameter Type Description
axis {x,y,z} or string Rotation axis, given either as a 3-vector or as an axis keyword string ("x", "y", "z", "-x", "-y", "-z"), exactly as for local coordinate systems. It is normalized internally, so it need not be a unit vector.
angle number Rotation angle in degrees.

Return value

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

Notes:

  • axis need not be a unit vector; it is normalized internally. A zero-length (or near-zero) axis falls back to an implementation-defined unit axis, so pass a well-defined non-zero axis for predictable results.
  • The inverse operation is pymath.rotation_from_quat.

Example:

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

-- the axis may also be given as a keyword:
local q2 = pymath.quat_from_rotation("z", 90)   -- same result

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.rotation_from_quat, pymath.quat_from_matrix, pymath.rotation_matrix, Axes and Directions

Clone this wiki locally