Quaternion — Aspose.3D FOSS for Python API Reference

Overview

Quaternion represents a unit quaternion used to encode 3D rotations. Unlike Euler angles, quaternions avoid gimbal lock and interpolate smoothly. The Transform.rotation property on a scene node stores a Quaternion.

The components are stored as (w, x, y, z) where w is the scalar part and (x, y, z) form the vector part.

from aspose.threed.utilities import Quaternion
import math

# Identity quaternion (no rotation)
q = Quaternion()   # w=1, x=0, y=0, z=0

# Rotation of 90 degrees around the Y axis
q = Quaternion.from_euler_angle(0.0, math.radians(90), 0.0)

Package: aspose.threed.utilities

from aspose.threed.utilities import Quaternion

Constructor

SignatureDescription
Quaternion()Identity quaternion (w=1, x=0, y=0, z=0)
Quaternion(w, x, y, z)Explicit component constructor

Properties

NameTypeDescription
wfloatScalar (real) part
xfloatVector x-component
yfloatVector y-component
zfloatVector z-component
lengthfloatMagnitude of the quaternion

Static Factory Methods

MethodReturn TypeDescription
Quaternion.from_euler_angle(pitch, yaw, roll)QuaternionConstructs from Euler angles in radians (pitch=X, yaw=Y, roll=Z). Also accepts a Vector3 as the first argument
Quaternion.from_angle_axis(angle, axis)QuaternionConstructs from an angle (radians) and a Vector3 axis
Quaternion.from_rotation(orig, dest)QuaternionShortest-arc rotation from direction orig to direction dest
Quaternion.interpolate(t, from_q, to_q)QuaternionSLERP interpolation; t in [0, 1]
Quaternion.slerp(t, v1, v2)QuaternionAlias for interpolate

Instance Methods

MethodReturn TypeDescription
normalize()QuaternionReturns a unit-length copy
conjugate()QuaternionReturns the conjugate (w, -x, -y, -z)
inverse()QuaternionReturns the multiplicative inverse; raises ValueError if length is zero
dot(q)floatDot product with another quaternion
concat(rhs)QuaternionHamilton product (composition of two rotations)
euler_angles()Vector3Extracts Euler angles (radians) as Vector3(roll, pitch, yaw)
to_matrix(translation=None)Matrix4Converts to a 4×4 rotation matrix; optionally embeds a translation Vector3
to_angle_axis(angle, axis)NoneDecomposes into angle (radians) and axis; results written to single-element lists angle[0] and axis[0]

Example

from aspose.threed import Scene
from aspose.threed.utilities import Quaternion, Vector3
import math

scene = Scene()
node = scene.root_node.create_child_node("rotated_box")

# Rotate 45 degrees around the Y axis
angle = math.radians(45)
q = Quaternion.from_euler_angle(0.0, angle, 0.0)
node.transform.rotation = q

# SLERP between two rotations
q_start = Quaternion.from_euler_angle(0, 0, 0)
q_end   = Quaternion.from_euler_angle(0, math.pi, 0)
q_mid   = Quaternion.slerp(0.5, q_start, q_end)

# Convert to matrix (useful for manual transforms)
mat = q.to_matrix()

# Extract Euler angles back
angles = q.euler_angles()   # Vector3(roll, pitch, yaw)
print(math.degrees(angles.y))   # ~45.0

See Also