Module MAPLEAF.Motion.CythonQuaternion

Classes

class Quaternion (...)

Use objects of this class to store orientation information - direction and rotation Elements are: [ scalar, xi, yj, zk ] where scalar, x, y, and z are scalars i,j, and k squared = -1 ij=k ji=-k jk=i kj=-i ki=j ik=-j

To define the rotation quaternion between two frames: If Q(2) = Q(1) * Q(1-2) Q(1)^-1 * Q(2) = Q(1)^-1 * Q(1) * Q(1-2) Q(1)^-1 * Q(2) = Q(1-2) ------------- where Q(1-2) defines the rotation from frame 1 to 2 (as defined in the first step) Q(2-1) = Q(1-2).conjugate

Quaternion normalization is not enforced by this class, but quaternions do not represent a rotation unless they are normalized. Quaternions are automatically normalized if this class is constructed using the angle/axis terms and if .rotate() is used.

Future: Could increase rotation performance by ~50% by converting to a rotation matrix Only worth it if we rotate many vectors per quaternion

A positive angle of rotation is clockwise if we are looking down the defined rotation axis

Class definition in CythonQuaternion.pxd

Can initialize in one of three ways: 1. orientation = Quaternion(axisOfRotation=Vector(0,0,1), angle=(pi)) - angle should be in radians 2. orientation = Quaternion(components=[0,1,0,1]) NOTE: Deprecated - will be removed 3. orientation = Quaternion(0, 1, 0, 1) - Fastest approach

Instance variables

var Q0

Return an attribute of instance, which is of type owner.

var Q1

Return an attribute of instance, which is of type owner.

var Q2

Return an attribute of instance, which is of type owner.

var Q3

Return an attribute of instance, which is of type owner.

Methods

def conjugate(...)

Negate all complex terms - produces an inverse rotation if the quaternion is a unit quaternion

def dotProduct(...)

Used to compute the angle parameter in spherical linear interpolation

def inverse(...)

Conjugate divided by self.norm

def norm(...)

Get the norm of the quaternion

def normalize(...)

Create unit quaternion

def plotRotation(...)
def rotate(...)

Use the quaternion to rotate a vector

def rotationAngle(...)

Returns the angle (radians) by which this quaternion rotates vectors about the rotationAxis

def rotationAxis(...)

Returns the axis about which this quaternion would rotate a vector

def scaleRotation(...)
def slerp(...)

Spherical Linear Interpolation - fraction = (0-1) where 0 is self, 1 is quat2

def toEulerAngles(...)

Returns Tait-Bryan 3-2-1, z-y-x convention Euler Angles Vector

def toRotationVector(...)