-
Notifications
You must be signed in to change notification settings - Fork 18
pymath.rotation_matrix
Daniel Flassig edited this page Jun 24, 2026
·
1 revision
Builds a rotation matrix, either 3×3 (rotation about an axis in space) or 2×2 (rotation in the plane).
The form is selected by the arguments: pass an axis and an angle for the 3×3 matrix, or a single angle for the 2×2 matrix.
This function is located in the pymath module.
mat = pymath.rotation_matrix(axis, angle) -- 3×3 rotation about axis
mat = pymath.rotation_matrix(angle) -- 2×2 planar rotation| Parameter | Type | Description |
|---|---|---|
axis |
{x,y,z} or string
|
(3×3 form only) Rotation axis, given as a 3-vector or as an axis keyword string ("x", "y", "z", "-x", "-y", "-z"), as for local coordinate systems. Normalized internally. |
angle |
number |
Rotation angle in degrees. |
| Type | Description |
|---|---|
mat |
A new rotation matrix, represented as an array of row-vectors. 3×3 when an axis is given, 2×2 when only an angle is given. |
- With two arguments you get the 3×3 axis rotation; with a single (numeric) argument the 2×2 planar rotation.
- All angles are in degrees.
- The 2×2 matrix is
{{cos θ, -sin θ}, {sin θ, cos θ}}. - The 3×3 form is equivalent to
pymath.matrix_from_quat(pymath.quat_from_rotation(axis, angle)).
-- 3×3: 90° about the z-axis
local R3 = pymath.rotation_matrix("z", 90)
-- R3 == {{0, -1, 0},
-- {1, 0, 0},
-- {0, 0, 1}}
-- 2×2: 90° in the plane
local R2 = pymath.rotation_matrix(90)
-- R2 == {{0, -1},
-- {1, 0}}Minimum PYTHA Version: V27
pymath, pymath.matrix_from_quat, pymath.matrix_from_euler_angles, pymath.quat_from_rotation, Axes and Directions