- class QQuaternion¶
The
QQuaternion
class represents a quaternion consisting of a vector and scalar. More…Added in version 4.6.
Synopsis¶
Methods¶
def
__init__()
def
__reduce__()
def
__repr__()
def
conjugated()
def
getAxes()
def
getEulerAngles()
def
inverted()
def
isIdentity()
def
isNull()
def
length()
def
lengthSquared()
def
normalize()
def
normalized()
def
__ne__()
def
__mul__()
def
__imul__()
def
__add__()
def
__iadd__()
def
__sub__()
def
__isub__()
def
__div__()
def
operator/=()
def
__eq__()
def
rotatedVector()
def
scalar()
def
setScalar()
def
setVector()
def
setX()
def
setY()
def
setZ()
def
toEulerAngles()
def
toVector4D()
def
vector()
def
x()
def
y()
def
z()
Static functions¶
def
dotProduct()
def
fromAxes()
def
fromDirection()
def
nlerp()
def
rotationTo()
def
slerp()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
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.
- __init__()¶
Constructs an identity quaternion (1, 0, 0, 0), i.e. with the vector (0, 0, 0) and scalar 1.
- __init__(vector)
- Parameters:
vector –
QVector4D
Constructs a quaternion from the components of
vector
.- __init__(scalar, vector)
- Parameters:
scalar – float
vector –
QVector3D
Constructs a quaternion vector from the specified
vector
andscalar
.- __init__(scalar, xpos, ypos, zpos)
- Parameters:
scalar – float
xpos – float
ypos – float
zpos – float
Constructs a quaternion with the vector (
xpos
,ypos
,zpos
) andscalar
.- __reduce__()¶
- Return type:
str
- __repr__()¶
- Return type:
str
- conjugated()¶
- Return type:
Returns the conjugate of this quaternion, which is (-x, -y, -z, scalar).
- static dotProduct(q1, q2)¶
- Parameters:
q1 –
QQuaternion
q2 –
QQuaternion
- Return type:
float
Returns the dot product of
q1
andq2
.See also
- static fromAxes(xAxis, yAxis, zAxis)¶
- Parameters:
- Return type:
Constructs the quaternion using 3 axes (
xAxis
,yAxis
,zAxis
).Creates a normalized quaternion that corresponds to rotating through
angle
degrees about the specified 3Daxis
.See also
- static fromAxisAndAngle(x, y, z, angle)
- Parameters:
x – float
y – float
z – float
angle – float
- Return type:
Creates a normalized quaternion that corresponds to rotating through
angle
degrees about the 3D axis (x
,y
,z
).See also
- static fromDirection(direction, up)¶
- Parameters:
- Return type:
Constructs the quaternion using specified forward direction
direction
and upward directionup
. If the upward direction was not specified or the forward and upward vectors are collinear, a new orthonormal upward direction will be generated.See also
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
- static fromEulerAngles(pitch, yaw, roll)
- Parameters:
pitch – float
yaw – float
roll – float
- Return type:
Creates a quaternion that corresponds to a rotation of
roll
degrees around the z axis,pitch
degrees around the x axis, andyaw
degrees around the y axis (in that order).See also
- static fromRotationMatrix(rot3x3)¶
- Parameters:
rot3x3 –
QMatrix3x3
- Return type:
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.
See also
Returns the 3 orthonormal axes (
xAxis
,yAxis
,zAxis
) defining the quaternion.See also
This is an overloaded function.
Extracts a 3D axis
axis
and a rotating angleangle
(in degrees) that corresponds to this quaternion.See also
- getEulerAngles()¶
- Return type:
(float, float, float)
Calculates
roll
,pitch
, andyaw
Euler angles (in degrees) that corresponds to this quaternion.See also
- inverted()¶
- Return type:
Returns the inverse of this quaternion. If this quaternion is null, then a null quaternion is returned.
- 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 returnsfalse
.- isNull()¶
- Return type:
bool
Returns
true
if the x, y, z, and scalar components of this quaternion are set to 0.0; otherwise returnsfalse
.- length()¶
- Return type:
float
Returns the length of the quaternion. This is also called the “norm”.
See also
- lengthSquared()¶
- Return type:
float
Returns the squared length of the quaternion.
Note
Though cheap to compute, this is susceptible to overflow and underflow that
length()
avoids in many cases.See also
- static nlerp(q1, q2, t)¶
- Parameters:
q1 –
QQuaternion
q2 –
QQuaternion
t – float
- Return type:
Interpolates along the shortest linear path between the rotational positions
q1
andq2
. The valuet
should be between 0 and 1, indicating the distance to travel betweenq1
andq2
. The result will benormalized()
.If
t
is less than or equal to 0, thenq1
will be returned. Ift
is greater than or equal to 1, thenq2
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
- 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.
See also
- normalized()¶
- Return type:
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
- __ne__(q2)¶
- Parameters:
q2 –
QQuaternion
- Return type:
bool
Returns
true
ifq1
is not equal toq2
; otherwise returnsfalse
. This operator uses an exact floating-point comparison.- __mul__(q2)¶
- Parameters:
q2 –
QQuaternion
- Return type:
Multiplies
q1
andq2
using quaternion multiplication. The result corresponds to applying both of the rotations specified byq1
andq2
.See also
operator*=()
- __mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given
quaternion
, multiplied by the givenfactor
.See also
operator*=()
- __mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given
quaternion
, multiplied by the givenfactor
.See also
operator*=()
- __imul__(quaternion)¶
- Parameters:
quaternion –
QQuaternion
- Return type:
Multiplies this quaternion by
quaternion
and returns a reference to this quaternion.- __imul__(factor)
- Parameters:
factor – float
- Return type:
Multiplies this quaternion’s components by the given
factor
, and returns a reference to this quaternion.See also
operator/=()
- __add__(q2)¶
- Parameters:
q2 –
QQuaternion
- Return type:
Returns a
QQuaternion
object that is the sum of the given quaternions,q1
andq2
; each component is added separately.See also
operator+=()
- __iadd__(quaternion)¶
- Parameters:
quaternion –
QQuaternion
- Return type:
Adds the given
quaternion
to this quaternion and returns a reference to this quaternion.See also
operator-=()
- __sub__()¶
- Return type:
This is an overloaded function.
Returns a
QQuaternion
object that is formed by changing the sign of all three components of the givenquaternion
.Equivalent to
QQuaternion(0,0,0,0) - quaternion
.- __sub__(q2)
- Parameters:
q2 –
QQuaternion
- Return type:
Returns a
QQuaternion
object that is formed by subtractingq2
fromq1
; each component is subtracted separately.See also
operator-=()
- __isub__(quaternion)¶
- Parameters:
quaternion –
QQuaternion
- Return type:
Subtracts the given
quaternion
from this quaternion and returns a reference to this quaternion.See also
operator+=()
- __div__(divisor)¶
- Parameters:
divisor – float
- Return type:
Returns the
QQuaternion
object formed by dividing all components of the givenquaternion
by the givendivisor
.See also
operator/=()
- operator/=(divisor)
- Parameters:
divisor – float
- Return type:
Divides this quaternion’s components by the given
divisor
, and returns a reference to this quaternion.See also
operator*=()
- __eq__(q2)¶
- Parameters:
q2 –
QQuaternion
- Return type:
bool
Returns
true
ifq1
is equal toq2
; otherwise returnsfalse
. This operator uses an exact floating-point comparison.Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Rotates
vector
with this quaternion to produce a new vector in 3D space. The following code:result = q.rotatedVector(vector)
is equivalent to the following:
result = (q * QQuaternion(0, vector) * q.conjugated()).vector()
- static rotationTo(from, to)¶
- Parameters:
- Return type:
Returns the shortest arc quaternion to rotate from the direction described by the vector
from
to the direction described by the vectorto
.See also
- scalar()¶
- Return type:
float
Returns the scalar component of this quaternion.
See also
- setScalar(scalar)¶
- Parameters:
scalar – float
Sets the scalar component of this quaternion to
scalar
.Sets the vector component of this quaternion to
vector
.See also
- setVector(x, y, z)
- Parameters:
x – float
y – float
z – float
Sets the vector component of this quaternion to (
x
,y
,z
).See also
- setX(x)¶
- Parameters:
x – float
Sets the x coordinate of this quaternion’s vector to the given
x
coordinate.See also
- setY(y)¶
- Parameters:
y – float
Sets the y coordinate of this quaternion’s vector to the given
y
coordinate.See also
- setZ(z)¶
- Parameters:
z – float
Sets the z coordinate of this quaternion’s vector to the given
z
coordinate.See also
- static slerp(q1, q2, t)¶
- Parameters:
q1 –
QQuaternion
q2 –
QQuaternion
t – float
- Return type:
Interpolates along the shortest spherical path between the rotational positions
q1
andq2
. The valuet
should be between 0 and 1, indicating the spherical distance to travel betweenq1
andq2
.If
t
is less than or equal to 0, thenq1
will be returned. Ift
is greater than or equal to 1, thenq2
will be returned.See also
This is an overloaded function.
Calculates roll, pitch, and yaw Euler angles (in degrees) that corresponds to this quaternion.
See also
- toRotationMatrix()¶
- Return type:
Creates a rotation matrix that corresponds to this quaternion.
Note
If this quaternion is not normalized, the resulting rotation matrix will contain scaling information.
See also
Returns this quaternion as a 4D vector.
Returns the vector component of this quaternion.
See also
- x()¶
- Return type:
float
Returns the x coordinate of this quaternion’s vector.
- y()¶
- Return type:
float
Returns the y coordinate of this quaternion’s vector.
- z()¶
- Return type:
float
Returns the z coordinate of this quaternion’s vector.