 Home · All Classes · Modules

QQuaternion Class Reference[QtGui module]

The QQuaternion class represents a quaternion consisting of a vector and scalar. More...

Static Methods

• QQuaternion fromAxisAndAngle (QVector3D axis, float angle)
• QQuaternion fromAxisAndAngle (float x, float y, float z, float angle)
• QQuaternion nlerp (QQuaternion q1, QQuaternion q2, float t)
• QQuaternion slerp (QQuaternion q1, QQuaternion q2, float t)

Special Methods

• QQuaternion __add__ (self, QQuaternion q2)
• QQuaternion __div__ (self, float divisor)
• bool __eq__ (self, QQuaternion q2)
• QQuaternion __iadd__ (self, QQuaternion quaternion)
• QQuaternion __idiv__ (self, float divisor)
• QQuaternion __imul__ (self, float factor)
• QQuaternion __imul__ (self, QQuaternion quaternion)
• QQuaternion __isub__ (self, QQuaternion quaternion)
• QQuaternion __mul__ (self, QQuaternion q2)
• QQuaternion __mul__ (self, QQuaternion quaternion)
• QQuaternion __mul__ (self, float factor)
• bool __ne__ (self, QQuaternion q2)
• QQuaternion __neg__ (self)
• str __repr__ (self)
• QQuaternion __sub__ (self, QQuaternion q2)

Detailed Description

This class can be pickled.

The QQuaternion class represents a quaternion consisting of a vector and scalar.

Quaternions are used to represent rotations in 3D space, and consist of a 3D rotation axis specified by the x, y, and z coordinates, and a scalar representing the rotation angle.

Method Documentation

QQuaternion.__init__ (self)

Constructs an identity quaternion, i.e. with coordinates (1, 0, 0, 0).

QQuaternion.__init__ (self, float aScalar, float xpos, float ypos, float zpos)

Constructs a quaternion with the vector (xpos, ypos, zpos) and scalar.

QQuaternion.__init__ (self, float aScalar, QVector3DaVector)

Constructs a quaternion vector from the specified vector and scalar.

QQuaternion.__init__ (self, QVector4DaVector)

Constructs a quaternion from the components of vector.

QQuaternion QQuaternion.conjugate (self)

Returns the conjugate of this quaternion, which is (-x, -y, -z, scalar).

QQuaternion QQuaternion.fromAxisAndAngle (QVector3Daxis, float angle)

Creates a normalized quaternion that corresponds to rotating through angle degrees about the specified 3D axis.

QQuaternion QQuaternion.fromAxisAndAngle (float x, float y, float z, float angle)

Creates a normalized quaternion that corresponds to rotating through angle degrees about the 3D axis (x, y, z).

bool QQuaternion.isIdentity (self)

Returns true if the x, y, and z components of this quaternion are set to 0.0, and the scalar component is set to 1.0; otherwise returns false.

bool QQuaternion.isNull (self)

Returns true if the x, y, z, and scalar components of this quaternion are set to 0.0; otherwise returns false.

float QQuaternion.length (self)

Returns the length of the quaternion. This is also called the "norm".

float QQuaternion.lengthSquared (self)

Returns the squared length of the quaternion.

QQuaternion QQuaternion.nlerp (QQuaternionq1, QQuaternionq2, float t)

Interpolates along the shortest linear path between the rotational positions q1 and q2. The value t should be between 0 and 1, indicating the distance to travel between q1 and q2. The result will be normalized().

If t is less than or equal to 0, then q1 will be returned. If t is greater than or equal to 1, then q2 will be returned.

The nlerp() function is typically faster than slerp() and will give approximate results to spherical interpolation that are good enough for some applications.

QQuaternion.normalize (self)

Normalizes the currect quaternion in place. Nothing happens if this is a null quaternion or the length of the quaternion is very close to 1.

QQuaternion QQuaternion.normalized (self)

Returns the normalized unit form of this quaternion.

If this quaternion is null, then a null quaternion is returned. If the length of the quaternion is very close to 1, then the quaternion will be returned as-is. Otherwise the normalized form of the quaternion of length 1 will be returned.

QVector3D QQuaternion.rotatedVector (self, QVector3Dvector)

Rotates vector with this quaternion to produce a new vector in 3D space. The following code:

QVector3D result = q.rotatedVector(vector);

is equivalent to the following:

QVector3D result = (q * QQuaternion(0, vector) * q.conjugate()).vector();

float QQuaternion.scalar (self)

Returns the scalar component of this quaternion.

QQuaternion.setScalar (self, float aScalar)

Sets the scalar component of this quaternion to scalar.

QQuaternion.setVector (self, QVector3DaVector)

Sets the vector component of this quaternion to vector.

QQuaternion.setVector (self, float aX, float aY, float aZ)

Sets the vector component of this quaternion to (x, y, z).

QQuaternion.setX (self, float aX)

Sets the x coordinate of this quaternion's vector to the given x coordinate.

QQuaternion.setY (self, float aY)

Sets the y coordinate of this quaternion's vector to the given y coordinate.

QQuaternion.setZ (self, float aZ)

Sets the z coordinate of this quaternion's vector to the given z coordinate.

QQuaternion QQuaternion.slerp (QQuaternionq1, QQuaternionq2, float t)

Interpolates along the shortest spherical path between the rotational positions q1 and q2. The value t should be between 0 and 1, indicating the spherical distance to travel between q1 and q2.

If t is less than or equal to 0, then q1 will be returned. If t is greater than or equal to 1, then q2 will be returned.

QVector4D QQuaternion.toVector4D (self)

Returns this quaternion as a 4D vector.

QVector3D QQuaternion.vector (self)

Returns the vector component of this quaternion.

float QQuaternion.x (self)

Returns the x coordinate of this quaternion's vector.

float QQuaternion.y (self)

Returns the y coordinate of this quaternion's vector.

float QQuaternion.z (self)

Returns the z coordinate of this quaternion's vector.

QQuaternion QQuaternion.__sub__ (self, QQuaternionq2)

 PyQt 4.9.4 for Windows Copyright © Riverbank Computing Ltd and Nokia 2012 Qt 4.8.2