To use pyquaternion, import the Quaternion class. You can create quaternions to represent rotations, rotate vectors using the .rotate() method, and chain rotations together using the * operator (note: quaternions are multiplied in reverse order of rotation).
pyquaternion assumes a right-handed coordinate system compatible with East-North-Up and North-East-Down conventions.
For smooth transitions between orientations, use Quaternion.intermediates() to generate an iterator of intermediate quaternions for interpolation.
from pyquaternion import Quaternion
import numpy
# Create a rotation of pi radians about the X axis
my_quaternion = Quaternion(axis=[1, 0, 0], angle=3.14159265)
# Rotate a vector
v = numpy.array([0., 0., 1.])
v_prime = my_quaternion.rotate(v)
# Chain rotations (q2 * q1 applies q1 then q2)
q1 = Quaternion(axis=[1, 0, 0], angle=3.14159265)
q2 = Quaternion(axis=[0, 1, 0], angle=3.14159265 / 2)
q3 = q2 * q1
# Interpolation
q0 = Quaternion(axis=[1, 1, 1], angle=0.0)
q1 = Quaternion(axis=[1, 1, 1], angle=2 * 3.14159265 / 3)
for q in Quaternion.intermediates(q0, q1, 8, include_endpoints=True):
print(q.rotate(v))