Quaternion Class

Holds a Quaternion object which can be used to manipulate rotations in various ways. Quaternions can be constructed using a few different ways to describe the initial rotation:

# From Euler Angles
q = tdu.Quaternion(tdu.Vector(30, 5, -5))
# From an angle and a rotation axis
q = tdu.Quaternion(30, tdu.Vector(0, 1, 0))
# From two vectors, rotate from the first vector to the second vector
q = tdu.Quaternion(tdu.Vector(1, 0, 0), tdu.Vector(0, 1, 0))
# From a set of 4 quaternion values
q = tdu.Quaternion(x, y, z, w)

See also Transform CHOP which accepts, manipulates and outputs quaternions as sets of CHOP channels.

Members

xfloat :

Get or set the x component of the quaternion.

yfloat :

Get or set the y component of the quaternion.

zfloat :

Get or set the z component of the quaternion.

wfloat :

Get or set the w component of the quaternion.

Methods

lerp(q2, factor)quaternion:

Returns the linear interpolation of the quaternion with another quaternion and an interpolation factor.

The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc. The interpolation factor must be between 0 and 1.

q3 = q.lerp(q2, factor)

length()float:

Returns the length of the quaternion.

l = q.length()

cross(q2)vector:

Returns the cross product of the quaternion and argument.

The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.

l = q.cross(q2)

rotate(vec)vector:

Rotates a vector using the current quaternion. Returns a new vector.

v2 = q.rotate(v1)

slerp(q2, factor)quaternion:

Returns the spherical interpolation of the quaternion with another quaternion and an interpolation factor.

The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.

q3 = q.slerp(q2, factor)

eulerAngles(order='xyz')tuple:

Returns euler angles in degrees as a tuple (i.e. pitch as x, yaw as y, roll as z) from current quaternion and a rotation order. The 'order' argument can be set to any valid rotation order which by default is set to 'xyz'.

r = q.eulerAngles(order='xyz')

fromEuler(order='xyz')tuple:

Returns and set the current quaternion from euler angles in degrees as a 3 inputs argument (i.e. pitch as x, yaw as y, roll as z). The 'order' argument can be set to any valid rotation order which by default is set to 'xyz'.

r = q.fromEuler(order='xyz')

axis()vector:

Returns the rotation axis vector of the quaternion.

v = q.axis()

dot(q2)float:

Returns the dot product of the quaternion and the argument.

The quaternion argument can be anything from which a quaternion can be derived ie. (x,y,z,w), Matrix, etc.

l = q.dot(q2)

exp()quaternion:

Returns the exponential of the quaternion as a new quaternion.

q2 = q.exp()

copy()quaternion:

Creates a copy of the quaternion with separate values.

log()quaternion:

Returns the natural logarithm of the current quaternion as a new quaternion.

l = q.log()

inverse()None:

Invert the quaternion in place.

q.inverse()

angle()float:

Returns the rotation angle (in degrees) of the quaternion.

a = q.angle()

Special Functions

Quaternion *= QuaternionQuaternion:

Applies the rotation of one quaternion to another quaternion.

# apply rotation of q2 to q1
q1 *= q2

TouchDesigner Build: