Quaternion¶
Quaternion¶
Represents a Quaternion rotation.
The Quaternion class provides a number of convenient functions and conversions.
import numpy as np
from pyrr import Quaternion, Matrix33, Matrix44, Vector3, Vector4
q = Quaternion()
# explicit creation
q = Quaternion.from_x_rotation(np.pi / 2.0)
q = Quaternion.from_matrix(Matrix33.identity())
q = Quaternion.from_matrix(Matrix44.identity())
# inferred conversions
q = Quaternion(Quaternion())
q = Quaternion(Matrix33.identity())
q = Quaternion(Matrix44.identity())
# apply one quaternion to another
q1 = Quaternion.from_y_rotation(np.pi / 2.0)
q2 = Quaternion.from_x_rotation(np.pi / 2.0)
q3 = q1 * q2
# extract a matrix from the quaternion
m33 = q3.matrix33
m44 = q3.matrix44
# convert from matrix back to quaternion
q4 = Quaternion(m44)
# rotate a quaternion by a matrix
q = Quaternion() * Matrix33.identity()
q = Quaternion() * Matrix44.identity()
# apply quaternion to a vector
v3 = Quaternion() * Vector3()
v4 = Quaternion() * Vector4()
# undo a rotation
q = Quaternion.from_x_rotation(np.pi / 2.0)
v = q * Vector3([1.,1.,1.])
# ~q is the same as q.conjugate
original = ~q * v
assert np.allclose(original, v)
# get the dot product of 2 Quaternions
dot = Quaternion() | Quaternion.from_x_rotation(np.pi / 2.0)
- class pyrr.objects.quaternion.Quaternion(value=None, dtype=None)[source]¶
- property angle¶
Returns the angle around the axis of rotation of this Quaternion as a float.
- property axis¶
Returns the axis of rotation of this Quaternion as a Vector3.
- property conjugate¶
Returns the conjugate of this Quaternion.
This is a Quaternion with the opposite rotation.
- cross(other)[source]¶
Returns the cross of this Quaternion and another.
This is the equivalent of combining Quaternion rotations (like Matrix multiplication).
- classmethod from_axis(axis, dtype=None)[source]¶
Creates a new Quaternion from an axis with angle magnitude.
- classmethod from_axis_rotation(axis, theta, dtype=None)[source]¶
Creates a new Quaternion with a rotation around the specified axis.
- classmethod from_eulers(eulers, dtype=None)[source]¶
Creates a Quaternion from the specified Euler angles.
- classmethod from_inverse_of_eulers(eulers, dtype=None)[source]¶
Creates a Quaternion from the inverse of the specified Euler angles.
- classmethod from_matrix(matrix, dtype=None)[source]¶
Creates a Quaternion from the specified Matrix (Matrix33 or Matrix44).
- classmethod from_x_rotation(theta, dtype=None)[source]¶
Creates a new Quaternion with a rotation around the X-axis.
- classmethod from_y_rotation(theta, dtype=None)[source]¶
Creates a new Quaternion with a rotation around the Y-axis.
- classmethod from_z_rotation(theta, dtype=None)[source]¶
Creates a new Quaternion with a rotation around the Z-axis.
- property inverse¶
Returns the inverse of this quaternion.
- property is_identity¶
Returns True if the Quaternion has no rotation (0.,0.,0.,1.).
- property length¶
Returns the length of this Quaternion.
- lerp(other, t)[source]¶
Interpolates between quat1 and quat2 by t. The parameter t is clamped to the range [0, 1]
- property matrix33¶
Returns a Matrix33 representation of this Quaternion.
- property matrix44¶
Returns a Matrix44 representation of this Quaternion.
- property negative¶
Returns the negative of the Quaternion.
- property normalised¶
Returns a normalized version of this Quaternion as a new Quaternion.
- property normalized¶
Returns a normalized version of this Quaternion as a new Quaternion.
- power(exponent)[source]¶
Returns a new Quaternion representing this Quaternion to the power of the exponent.
- slerp(other, t)[source]¶
Spherically interpolates between quat1 and quat2 by t. The parameter t is clamped to the range [0, 1]
- w¶
The W value of this Quaternion.
- x¶
The X value of this Quaternion.
- xw¶
The X,W value of this Quaternion as a numpy.ndarray.
- xy¶
The X,Y value of this Quaternion as a numpy.ndarray.
- xyw¶
The X,Y,W value of this Quaternion as a numpy.ndarray.
- xyz¶
The X,Y,Z value of this Quaternion as a numpy.ndarray.
- xyzw¶
The X,Y,Z,W value of this Quaternion as a numpy.ndarray.
- xz¶
The X,Z value of this Quaternion as a numpy.ndarray.
- xzw¶
The X,Z,W value of this Quaternion as a numpy.ndarray.
- y¶
The Y value of this Quaternion.
- z¶
The Z value of this Quaternion.