QQuaternion

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

Inheritance diagram of PySide2.QtGui.QQuaternion

New in version 4.6.

Synopsis

Functions

Static functions

Detailed Description

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.

class QQuaternion

QQuaternion(vector)

QQuaternion(scalar, vector)

QQuaternion(scalar, xpos, ypos, zpos)

param ypos

float

param scalar

float

param zpos

float

param vector

QVector4D

param xpos

float

Constructs an identity quaternion (1, 0, 0, 0), i.e. with the vector (0, 0, 0) and scalar 1.

Constructs a quaternion vector from the specified vector and scalar .

See also

vector() scalar()

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

PySide2.QtGui.QQuaternion.__reduce__()
Return type

PyObject

PySide2.QtGui.QQuaternion.__repr__()
Return type

PyObject

PySide2.QtGui.QQuaternion.conjugate()
Return type

QQuaternion

Note

This function is deprecated.

Use conjugated() instead.

PySide2.QtGui.QQuaternion.conjugated()
Return type

QQuaternion

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

static PySide2.QtGui.QQuaternion.dotProduct(q1, q2)
Parameters
Return type

float

Returns the dot product of q1 and q2 .

See also

length()

static PySide2.QtGui.QQuaternion.fromAxes(xAxis, yAxis, zAxis)
Parameters
Return type

QQuaternion

Constructs the quaternion using 3 axes (xAxis , yAxis , zAxis ).

Note

The axes are assumed to be orthonormal.

static PySide2.QtGui.QQuaternion.fromAxisAndAngle(axis, angle)
Parameters
Return type

QQuaternion

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

See also

getAxisAndAngle()

static PySide2.QtGui.QQuaternion.fromAxisAndAngle(x, y, z, angle)
Parameters
  • xfloat

  • yfloat

  • zfloat

  • anglefloat

Return type

QQuaternion

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

See also

getAxisAndAngle()

static PySide2.QtGui.QQuaternion.fromDirection(direction, up)
Parameters
Return type

QQuaternion

Constructs the quaternion using specified forward direction direction and upward direction up . If the upward direction was not specified or the forward and upward vectors are collinear, a new orthonormal upward direction will be generated.

static PySide2.QtGui.QQuaternion.fromEulerAngles(eulerAngles)
Parameters

eulerAnglesQVector3D

Return type

QQuaternion

This is an overloaded function.

Creates a quaternion that corresponds to a rotation of eulerAngles : eulerAngles. z() degrees around the z axis, eulerAngles. x() degrees around the x axis, and eulerAngles. y() degrees around the y axis (in that order).

See also

toEulerAngles()

static PySide2.QtGui.QQuaternion.fromEulerAngles(pitch, yaw, roll)
Parameters
  • pitchfloat

  • yawfloat

  • rollfloat

Return type

QQuaternion

Creates a quaternion that corresponds to a rotation of roll degrees around the z axis, pitch degrees around the x axis, and yaw degrees around the y axis (in that order).

See also

getEulerAngles()

static PySide2.QtGui.QQuaternion.fromRotationMatrix(rot3x3)
Parameters

rot3x3QMatrix3x3

Return type

QQuaternion

Creates a quaternion that corresponds to a rotation matrix rot3x3 .

Note

If a given rotation matrix is not normalized, the resulting quaternion will contain scaling information.

PySide2.QtGui.QQuaternion.getAxes(xAxis, yAxis, zAxis)
Parameters

Returns the 3 orthonormal axes (xAxis , yAxis , zAxis ) defining the quaternion.

PySide2.QtGui.QQuaternion.inverted()
Return type

QQuaternion

Returns the inverse of this quaternion. If this quaternion is null, then a null quaternion is returned.

See also

isNull() length()

PySide2.QtGui.QQuaternion.isIdentity()
Return type

bool

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 .

PySide2.QtGui.QQuaternion.isNull()
Return type

bool

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

PySide2.QtGui.QQuaternion.length()
Return type

float

Returns the length of the quaternion. This is also called the “norm”.

PySide2.QtGui.QQuaternion.lengthSquared()
Return type

float

Returns the squared length of the quaternion.

static PySide2.QtGui.QQuaternion.nlerp(q1, q2, t)
Parameters
Return type

QQuaternion

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 function is typically faster than slerp() and will give approximate results to spherical interpolation that are good enough for some applications.

See also

slerp()

PySide2.QtGui.QQuaternion.normalize()

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

PySide2.QtGui.QQuaternion.normalized()
Return type

QQuaternion

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.

PySide2.QtGui.QQuaternion.__ne__(q2)
Parameters

q2QQuaternion

Return type

bool

PySide2.QtGui.QQuaternion.__mul__(q2)
Parameters

q2QQuaternion

Return type

QQuaternion

PySide2.QtGui.QQuaternion.__mul__(factor)
Parameters

factorfloat

Return type

QQuaternion

PySide2.QtGui.QQuaternion.__mul__(factor)
Parameters

factorfloat

Return type

QQuaternion

PySide2.QtGui.QQuaternion.__imul__(quaternion)
Parameters

quaternionQQuaternion

Return type

QQuaternion

PySide2.QtGui.QQuaternion.__imul__(factor)
Parameters

factorfloat

Return type

QQuaternion

Multiplies this quaternion’s components by the given factor , and returns a reference to this quaternion.

See also

operator/=()

PySide2.QtGui.QQuaternion.__add__(q2)
Parameters

q2QQuaternion

Return type

QQuaternion

PySide2.QtGui.QQuaternion.__iadd__(quaternion)
Parameters

quaternionQQuaternion

Return type

QQuaternion

Adds the given quaternion to this quaternion and returns a reference to this quaternion.

See also

operator-=()

PySide2.QtGui.QQuaternion.__sub__()
Return type

QQuaternion

PySide2.QtGui.QQuaternion.__sub__(q2)
Parameters

q2QQuaternion

Return type

QQuaternion

PySide2.QtGui.QQuaternion.__isub__(quaternion)
Parameters

quaternionQQuaternion

Return type

QQuaternion

Subtracts the given quaternion from this quaternion and returns a reference to this quaternion.

See also

operator+=()

PySide2.QtGui.QQuaternion.__div__(divisor)
Parameters

divisorfloat

Return type

QQuaternion

PySide2.QtGui.QQuaternion.__idiv__(divisor)
Parameters

divisorfloat

Return type

QQuaternion

Divides this quaternion’s components by the given divisor , and returns a reference to this quaternion.

See also

operator*=()

PySide2.QtGui.QQuaternion.__eq__(q2)
Parameters

q2QQuaternion

Return type

bool

PySide2.QtGui.QQuaternion.rotatedVector(vector)
Parameters

vectorQVector3D

Return type

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.conjugated()).vector();
static PySide2.QtGui.QQuaternion.rotationTo(from, to)
Parameters
Return type

QQuaternion

Returns the shortest arc quaternion to rotate from the direction described by the vector from to the direction described by the vector to .

See also

fromDirection()

PySide2.QtGui.QQuaternion.scalar()
Return type

float

Returns the scalar component of this quaternion.

See also

setScalar() x() y() z()

PySide2.QtGui.QQuaternion.setScalar(scalar)
Parameters

scalarfloat

Sets the scalar component of this quaternion to scalar .

PySide2.QtGui.QQuaternion.setVector(vector)
Parameters

vectorQVector3D

Sets the vector component of this quaternion to vector .

PySide2.QtGui.QQuaternion.setVector(x, y, z)
Parameters
  • xfloat

  • yfloat

  • zfloat

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

PySide2.QtGui.QQuaternion.setX(x)
Parameters

xfloat

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

PySide2.QtGui.QQuaternion.setY(y)
Parameters

yfloat

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

PySide2.QtGui.QQuaternion.setZ(z)
Parameters

zfloat

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

static PySide2.QtGui.QQuaternion.slerp(q1, q2, t)
Parameters
Return type

QQuaternion

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()

PySide2.QtGui.QQuaternion.toEulerAngles()
Return type

QVector3D

This is an overloaded function.

Calculates roll, pitch, and yaw Euler angles (in degrees) that corresponds to this quaternion.

PySide2.QtGui.QQuaternion.toRotationMatrix()
Return type

QMatrix3x3

Creates a rotation matrix that corresponds to this quaternion.

Note

If this quaternion is not normalized, the resulting rotation matrix will contain scaling information.

PySide2.QtGui.QQuaternion.toVector4D()
Return type

QVector4D

Returns this quaternion as a 4D vector.

PySide2.QtGui.QQuaternion.vector()
Return type

QVector3D

Returns the vector component of this quaternion.

PySide2.QtGui.QQuaternion.x()
Return type

float

Returns the x coordinate of this quaternion’s vector.

See also

setX() y() z() scalar()

PySide2.QtGui.QQuaternion.y()
Return type

float

Returns the y coordinate of this quaternion’s vector.

See also

setY() x() z() scalar()

PySide2.QtGui.QQuaternion.z()
Return type

float

Returns the z coordinate of this quaternion’s vector.

See also

setZ() x() y() scalar()