Quaternion Class

From Derivative
Jump to: navigation, search

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)



Members

tdu.Quaternion.wfloat :

Get or set the w component of the quaternion.

tdu.Quaternion.xfloat :

Get or set the x component of the quaternion.

tdu.Quaternion.yfloat :

Get or set the y component of the quaternion.

tdu.Quaternion.zfloat :

Get or set the z component of the quaternion.

Methods

tdu.Quaternion.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)

tdu.Quaternion.length()float:

Returns the length of the quaternion.
l = q.length()

tdu.Quaternion.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)

tdu.Quaternion.rotate(vec)vector:

Rotates a vector using the current quaternion. Returns a new vector.
v2 = q.rotate(v1)

tdu.Quaternion.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)

tdu.Quaternion.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')

tdu.Quaternion.axis()vector:

Returns the rotation axis vector of the quaternion.
v = q.axis()

tdu.Quaternion.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)

tdu.Quaternion.exp()quaternion:

Returns the exponential of the quaternion as a new quaternion.
q2 = q.exp()

tdu.Quaternion.copy()quaternion:

Creates a copy of the quaternion with separate values.

tdu.Quaternion.log()quaternion:

Returns the natural logarithm of the current quaternion as a new quaternion.
l = q.log()

tdu.Quaternion.inverse()None:

Invert the quaternion in place.
q.inverse()

tdu.Quaternion.angle()float:

Returns the rotation angle (in degrees) of the quaternion.
a = q.angle()