|  | Home · All Classes · Modules

# QQuaternion Class Reference
[QtGui module]

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

### Methods

- __init__ (self)
- __init__ (self, float, float, float, float)
- __init__ (self, float, QVector3D)
- __init__ (self, QVector4D)
- __init__ (self, QQuaternion)
- QQuaternion conjugate (self)
- bool isIdentity (self)
- bool isNull (self)
- float length (self)
- float lengthSquared (self)
- normalize (self)
- QQuaternion normalized (self)
- QVector3D rotatedVector (self, QVector3D)
- float scalar (self)
- setScalar (self, float)
- setVector (self, QVector3D)
- setVector (self, float, float, float)
- setX (self, float)
- setY (self, float)
- setZ (self, float)
- QVector4D toVector4D (self)
- QVector3D vector (self)
- float x (self)
- float y (self)
- float z (self)

### Static Methods

- QQuaternion fromAxisAndAngle (QVector3D, float)
- QQuaternion fromAxisAndAngle (float, float, float, float)
- QQuaternion nlerp (QQuaternion, QQuaternion, float)
- QQuaternion slerp (QQuaternion, QQuaternion, float)

### Special Methods

- QQuaternion __add__ (self, QQuaternion)
- QQuaternion __div__ (self, float)
- bool __eq__ (self, QQuaternion)
- QQuaternion __iadd__ (self, QQuaternion)
- QQuaternion __idiv__ (self, float)
- QQuaternion __imul__ (self, float)
- QQuaternion __imul__ (self, QQuaternion)
- QQuaternion __isub__ (self, QQuaternion)
- QQuaternion __mul__ (self, QQuaternion)
- QQuaternion __mul__ (self, QQuaternion)
- QQuaternion __mul__ (self, float)
- bool __ne__ (self, QQuaternion)
- QQuaternion __neg__ (self, QQuaternion)
- str __repr__ (self)
- QQuaternion __sub__ (self, QQuaternion)

## 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, float, float, float)

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

### QQuaternion.__init__ (self, float, QVector3D)

Constructs a quaternion vector from the specified vector and scalar.

See also vector() and scalar().

### QQuaternion.__init__ (self, QVector4D)

Constructs a quaternion from the components of vector.

### QQuaternion.__init__ (self, QQuaternion)

### QQuaternion QQuaternion.conjugate (self)

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

### QQuaternion QQuaternion.fromAxisAndAngle (QVector3D, float)

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

### QQuaternion QQuaternion.fromAxisAndAngle (float, float, float, float)

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".

See also lengthSquared() and normalized().

### float QQuaternion.lengthSquared (self)

Returns the squared length of the quaternion.

See also length().

### QQuaternion QQuaternion.nlerp (QQuaternion, QQuaternion, float)

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.

See also slerp().

### 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.

See also length() and normalized().

### 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.

See also length() and normalize().

### QVector3D QQuaternion.rotatedVector (self, QVector3D)

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.

See also setScalar(), x(), y(), and z().

### QQuaternion.setScalar (self, float)

Sets the scalar component of this quaternion to scalar.

See also scalar(), setX(), setY(), and setZ().

### QQuaternion.setVector (self, QVector3D)

Sets the vector component of this quaternion to vector.

See also vector() and setScalar().

### QQuaternion.setVector (self, float, float, float)

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

See also vector() and setScalar().

### QQuaternion.setX (self, float)

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

See also x(), setY(), setZ(), and setScalar().

### QQuaternion.setY (self, float)

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

See also y(), setX(), setZ(), and setScalar().

### QQuaternion.setZ (self, float)

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

See also z(), setX(), setY(), and setScalar().

### QQuaternion QQuaternion.slerp (QQuaternion, QQuaternion, float)

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.

See also nlerp().

### QVector4D QQuaternion.toVector4D (self)

Returns this quaternion as a 4D vector.

### QVector3D QQuaternion.vector (self)

Returns the vector component of this quaternion.

See also setVector() and scalar().

### float QQuaternion.x (self)

Returns the x coordinate of this quaternion's vector.

See also setX(), y(), z(), and scalar().

### float QQuaternion.y (self)

Returns the y coordinate of this quaternion's vector.

See also setY(), x(), z(), and scalar().

### float QQuaternion.z (self)

Returns the z coordinate of this quaternion's vector.

See also setZ(), x(), y(), and scalar().

### QQuaternion QQuaternion.__add__ (self, QQuaternion)

### QQuaternion QQuaternion.__div__ (self, float)

### bool QQuaternion.__eq__ (self, QQuaternion)

### QQuaternion QQuaternion.__iadd__ (self, QQuaternion)

### QQuaternion QQuaternion.__idiv__ (self, float)

### QQuaternion QQuaternion.__imul__ (self, float)

### QQuaternion QQuaternion.__imul__ (self, QQuaternion)

### QQuaternion QQuaternion.__isub__ (self, QQuaternion)

### QQuaternion QQuaternion.__mul__ (self, QQuaternion)

### QQuaternion QQuaternion.__mul__ (self, float)

### bool QQuaternion.__ne__ (self, QQuaternion)

### QQuaternion QQuaternion.__neg__ (self, QQuaternion)

### str QQuaternion.__repr__ (self)

### QQuaternion QQuaternion.__sub__ (self, QQuaternion)