A quat represents a quaternion type that can be used to store rotations. A quaternion contains four values of which one can be seen as the angle and the other three as the axis of rotation. The most common way to initialize a quaternion is by specifying an angle (in radians) and the axis of rotation:
# initialize the quaternion by specifying an angle and the axis of rotation
q = quat(0.5*pi, vec3(0,0,1))
# initialize by specifying a rotation matrix (as mat3 or mat4)
q = quat(R)
# all components are set to zero
q = quat()
(0.0000, 0.0000, 0.0000, 0.0000)
# set the w component
q = quat(2.5)
(0.5000, 0.0000, 0.0000, 0.0000)
# set all four components (w,x,y,z)
q = quat(1,0,0,0)
q = quat([1,0,0,0])
q = quat("1,0,0,0")
(1.0000, 0.0000, 0.0000, 0.0000)
Finally, you can initialize a quaternion with a copy of another quaternion:
q = quat(r)
Mathematical operations
The mathematical operators are supported with the following combination of types:
quat = quat + quat quat = quat - quat quat = quat * quat quat = float * quat quat = quat * float quat = quat / float quat = -quat quat = quat ** float = pow(quat, float) (new in version 1.1) quat = quat ** quat = pow(quat, quat) (new in version 1.1)
Additionally, you can compare quaternions with == and !=.
Taking the absolute value will return the magnitude of the quaternion:
float = abs(q)
Methods
| ) |
| ) |
| ) |
| ) |
| angle, axis) |
| ) |
| ) |
| matrix) |
| b) |
| ) |
| ) |
| v) |
self*v*self.conjugate() and turning the result back into a vec3.
Related functions
| t, q0, q1, shortest=True) |
True the interpolation will always
be along the shortest path, otherwise it depends on the orientation of
the input quaternions whether the shortest or longest path will be taken
(you can switch between the paths by negating either q0 or q1).
| t, a, b, c, d) |