QQuaternion 类

QQuaternion 类表示由向量和标量组成的四元数。 更多...

头: #include <QQuaternion>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

公共函数

QQuaternion ()
QQuaternion (float scalar , float xpos , float ypos , float zpos )
QQuaternion (float scalar , const QVector3D & vector )
QQuaternion (const QVector4D & vector )
QQuaternion conjugated () const
void getAxes (QVector3D * xAxis , QVector3D * yAxis , QVector3D * zAxis ) const
void getAxisAndAngle (float * x , float * y , float * z , float * angle ) const
void getAxisAndAngle (QVector3D * axis , float * angle ) const
void getEulerAngles (float * pitch , float * yaw , float * roll ) const
QQuaternion inverted () const
bool isIdentity () const
bool isNull () const
float length () const
float lengthSquared () const
void normalize ()
QQuaternion normalized () const
QVector3D rotatedVector (const QVector3D & vector ) const
float scalar () const
void setScalar (float scalar )
void setVector (const QVector3D & vector )
void setVector (float x , float y , float z )
void setX (float x )
void setY (float y )
void setZ (float z )
QVector3D toEulerAngles () const
QMatrix3x3 toRotationMatrix () const
QVector4D toVector4D () const
QVector3D vector () const
float x () const
float y () const
float z () const
QVariant operator QVariant () const
QQuaternion & operator*= (float factor )
QQuaternion & operator*= (const QQuaternion & quaternion )
QQuaternion & operator+= (const QQuaternion & quaternion )
QQuaternion & operator-= (const QQuaternion & quaternion )
QQuaternion & operator/= (float divisor )

静态公共成员

float dotProduct (const QQuaternion & q1 , const QQuaternion & q2 )
QQuaternion fromAxes (const QVector3D & xAxis , const QVector3D & yAxis , const QVector3D & zAxis )
QQuaternion fromAxisAndAngle (const QVector3D & axis , float angle )
QQuaternion fromAxisAndAngle (float x , float y , float z , float angle )
QQuaternion fromDirection (const QVector3D & direction , const QVector3D & up )
QQuaternion fromEulerAngles (float pitch , float yaw , float roll )
QQuaternion fromEulerAngles (const QVector3D & eulerAngles )
QQuaternion fromRotationMatrix (const QMatrix3x3 & rot3x3 )
QQuaternion nlerp (const QQuaternion & q1 , const QQuaternion & q2 , float t )
QQuaternion rotationTo (const QVector3D & from , const QVector3D & to )
QQuaternion slerp (const QQuaternion & q1 , const QQuaternion & q2 , float t )
bool qFuzzyCompare (const QQuaternion & q1 , const QQuaternion & q2 )
bool operator!= (const QQuaternion & q1 , const QQuaternion & q2 )
QQuaternion operator* (float factor , const QQuaternion & quaternion )
QQuaternion operator* (const QQuaternion & quaternion , float factor )
QQuaternion operator* (const QQuaternion & q1 , const QQuaternion & q2 )
QVector3D operator* (const QQuaternion & quaternion , const QVector3D & vec )
QQuaternion operator+ (const QQuaternion & q1 , const QQuaternion & q2 )
QQuaternion operator- (const QQuaternion & q1 , const QQuaternion & q2 )
QQuaternion operator- (const QQuaternion & quaternion )
QQuaternion operator/ (const QQuaternion & quaternion , float divisor )
QDataStream & operator<< (QDataStream & stream , const QQuaternion & quaternion )
bool operator== (const QQuaternion & q1 , const QQuaternion & q2 )
QDataStream & operator>> (QDataStream & stream , QQuaternion & quaternion )

详细描述

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.

成员函数文档编制

[constexpr noexcept] QQuaternion:: QQuaternion ()

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

[constexpr noexcept] QQuaternion:: QQuaternion ( float scalar , float xpos , float ypos , float zpos )

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

[constexpr noexcept] QQuaternion:: QQuaternion ( float scalar , const QVector3D & vector )

Constructs a quaternion vector from the specified vector and scalar .

另请参阅 vector () 和 scalar ().

[explicit constexpr noexcept] QQuaternion:: QQuaternion (const QVector4D & vector )

构造四元数从分量为 vector .

[constexpr noexcept] QQuaternion QQuaternion:: conjugated () const

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

[static constexpr noexcept] float QQuaternion:: dotProduct (const QQuaternion & q1 , const QQuaternion & q2 )

返回点积为 q1 and q2 .

另请参阅 length ().

[static] QQuaternion QQuaternion:: fromAxes (const QVector3D & xAxis , const QVector3D & yAxis , const QVector3D & zAxis )

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

注意: The axes are assumed to be orthonormal.

另请参阅 getAxes () 和 fromRotationMatrix ().

[static] QQuaternion QQuaternion:: fromAxisAndAngle (const QVector3D & axis , float angle )

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

另请参阅 getAxisAndAngle ().

[static] 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 ).

另请参阅 getAxisAndAngle ().

[static] QQuaternion QQuaternion:: fromDirection (const QVector3D & direction , const QVector3D & up )

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.

另请参阅 fromAxes () 和 rotationTo ().

[static] QQuaternion QQuaternion:: fromEulerAngles ( float pitch , float yaw , float roll )

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

另请参阅 getEulerAngles ().

[static] QQuaternion QQuaternion:: fromEulerAngles (const QVector3D & eulerAngles )

这是重载函数。

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

另请参阅 toEulerAngles ().

[static] QQuaternion QQuaternion:: fromRotationMatrix (const QMatrix3x3 & rot3x3 )

Creates a quaternion that corresponds to a rotation matrix rot3x3 .

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

另请参阅 toRotationMatrix () 和 fromAxes ().

void QQuaternion:: getAxes ( QVector3D * xAxis , QVector3D * yAxis , QVector3D * zAxis ) const

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

另请参阅 fromAxes () 和 toRotationMatrix ().

void QQuaternion:: getAxisAndAngle ( float * x , float * y , float * z , float * angle ) const

Extracts a 3D axis ( x , y , z ) and a rotating angle angle (in degrees) that corresponds to this quaternion.

另请参阅 fromAxisAndAngle ().

void QQuaternion:: getAxisAndAngle ( QVector3D * axis , float * angle ) const

这是重载函数。

Extracts a 3D axis axis and a rotating angle angle (in degrees) that corresponds to this quaternion.

另请参阅 fromAxisAndAngle ().

void QQuaternion:: getEulerAngles ( float * pitch , float * yaw , float * roll ) const

计算 roll , pitch ,和 yaw Euler angles (in degrees) that corresponds to this quaternion.

另请参阅 fromEulerAngles ().

[constexpr noexcept] QQuaternion QQuaternion:: inverted () const

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

另请参阅 isNull () 和 length ().

[constexpr noexcept] bool QQuaternion:: isIdentity () const

返回 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 .

[constexpr noexcept] bool QQuaternion:: isNull () const

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

float QQuaternion:: length () const

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

另请参阅 lengthSquared (), normalized (),和 dotProduct ().

float QQuaternion:: lengthSquared () const

Returns the squared length of the quaternion.

注意: Though cheap to compute, this is susceptible to overflow and underflow that length () avoids in many cases.

另请参阅 length () 和 dotProduct ().

[static] QQuaternion QQuaternion:: nlerp (const QQuaternion & q1 , const QQuaternion & q2 , float t )

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

t is less than or equal to 0, then q1 will be returned. If t is greater than or equal to 1, then q2 将被返回。

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

另请参阅 slerp ().

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

另请参阅 length () 和 normalized ().

QQuaternion QQuaternion:: normalized () const

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.

另请参阅 normalize (), length (),和 dotProduct ().

QVector3D QQuaternion:: rotatedVector (const QVector3D & vector ) const

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

QVector3D result = q.rotatedVector(vector);
					

相当于以下:

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

[static] QQuaternion QQuaternion:: rotationTo (const QVector3D & from , const QVector3D & to )

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

另请参阅 fromDirection ().

[constexpr noexcept] float QQuaternion:: scalar () const

Returns the scalar component of this quaternion.

另请参阅 setScalar (), x (), y (),和 z ().

[constexpr noexcept] void QQuaternion:: setScalar ( float scalar )

Sets the scalar component of this quaternion to scalar .

另请参阅 scalar (), setX (), setY (),和 setZ ().

[constexpr noexcept] void QQuaternion:: setVector (const QVector3D & vector )

Sets the vector component of this quaternion to vector .

另请参阅 vector () 和 setScalar ().

[constexpr noexcept] void QQuaternion:: setVector ( float x , float y , float z )

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

另请参阅 vector () 和 setScalar ().

[constexpr noexcept] void QQuaternion:: setX ( float x )

Sets the x coordinate of this quaternion's vector to the given x 坐标。

另请参阅 x (), setY (), setZ (),和 setScalar ().

[constexpr noexcept] void QQuaternion:: setY ( float y )

Sets the y coordinate of this quaternion's vector to the given y 坐标。

另请参阅 y (), setX (), setZ (),和 setScalar ().

[constexpr noexcept] void QQuaternion:: setZ ( float z )

Sets the z coordinate of this quaternion's vector to the given z 坐标。

另请参阅 z (), setX (), setY (),和 setScalar ().

[static] QQuaternion QQuaternion:: slerp (const QQuaternion & q1 , const QQuaternion & q2 , float t )

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

t is less than or equal to 0, then q1 will be returned. If t is greater than or equal to 1, then q2 将被返回。

另请参阅 nlerp ().

QVector3D QQuaternion:: toEulerAngles () const

这是重载函数。

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

另请参阅 fromEulerAngles ().

QMatrix3x3 QQuaternion:: toRotationMatrix () const

Creates a rotation matrix that corresponds to this quaternion.

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

另请参阅 fromRotationMatrix () 和 getAxes ().

[constexpr noexcept] QVector4D QQuaternion:: toVector4D () const

Returns this quaternion as a 4D vector.

[constexpr noexcept] QVector3D QQuaternion:: vector () const

Returns the vector component of this quaternion.

另请参阅 setVector () 和 scalar ().

[constexpr noexcept] float QQuaternion:: x () const

Returns the x coordinate of this quaternion's vector.

另请参阅 setX (), y (), z (),和 scalar ().

[constexpr noexcept] float QQuaternion:: y () const

Returns the y coordinate of this quaternion's vector.

另请参阅 setY (), x (), z (),和 scalar ().

[constexpr noexcept] float QQuaternion:: z () const

Returns the z coordinate of this quaternion's vector.

另请参阅 setZ (), x (), y (),和 scalar ().

QVariant QQuaternion:: operator QVariant () const

Returns the quaternion as a QVariant .

[constexpr noexcept] QQuaternion &QQuaternion:: operator*= ( float factor )

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

另请参阅 operator/= ().

[constexpr noexcept] QQuaternion &QQuaternion:: operator*= (const QQuaternion & quaternion )

Multiplies this quaternion by quaternion and returns a reference to this quaternion.

[constexpr noexcept] QQuaternion &QQuaternion:: operator+= (const QQuaternion & quaternion )

添加给定 quaternion to this quaternion and returns a reference to this quaternion.

另请参阅 operator-= ().

[constexpr noexcept] QQuaternion &QQuaternion:: operator-= (const QQuaternion & quaternion )

减去给定 quaternion from this quaternion and returns a reference to this quaternion.

另请参阅 operator+= ().

[constexpr] QQuaternion &QQuaternion:: operator/= ( float divisor )

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

另请参阅 operator*= ().

相关非成员

[constexpr noexcept] bool qFuzzyCompare (const QQuaternion & q1 , const QQuaternion & q2 )

返回 true if q1 and q2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.

[constexpr noexcept] bool operator!= (const QQuaternion & q1 , const QQuaternion & q2 )

返回 true if q1 不等于 q2 ;否则返回 false 。此运算符使用精确浮点比较。

[constexpr noexcept] QQuaternion operator* ( float factor , const QQuaternion & quaternion )

返回副本为给定 quaternion ,乘以给定 factor .

另请参阅 QQuaternion::operator*= ().

[constexpr noexcept] QQuaternion operator* (const QQuaternion & quaternion , float factor )

返回副本为给定 quaternion ,乘以给定 factor .

另请参阅 QQuaternion::operator*= ().

[constexpr noexcept] QQuaternion operator* (const QQuaternion & q1 , const QQuaternion & q2 )

Multiplies q1 and q2 using quaternion multiplication. The result corresponds to applying both of the rotations specified by q1 and q2 .

另请参阅 QQuaternion::operator*= ().

QVector3D operator* (const QQuaternion & quaternion , const QVector3D & vec )

Rotates a vector vec with a quaternion quaternion to produce a new vector in 3D space.

[constexpr noexcept] QQuaternion operator+ (const QQuaternion & q1 , const QQuaternion & q2 )

返回 QQuaternion object that is the sum of the given quaternions, q1 and q2 ;分别相加各分量。

另请参阅 QQuaternion::operator+= ().

[constexpr noexcept] QQuaternion operator- (const QQuaternion & q1 , const QQuaternion & q2 )

返回 QQuaternion 对象的形成是通过减去 q2 from q1 ;分别减去各分量。

另请参阅 QQuaternion::operator-= ().

[constexpr noexcept] QQuaternion operator- (const QQuaternion & quaternion )

这是重载函数。

返回 QQuaternion object that is formed by changing the sign of all three components of the given quaternion .

相当于 QQuaternion(0,0,0,0) - quaternion .

[constexpr] QQuaternion operator/ (const QQuaternion & quaternion , float divisor )

返回 QQuaternion object formed by dividing all components of the given quaternion 通过给定 divisor .

另请参阅 QQuaternion::operator/= ().

QDataStream & operator<< ( QDataStream & stream , const QQuaternion & quaternion )

写入给定 quaternion 到给定 stream 并返回流引用。

另请参阅 序列化 Qt 数据类型 .

[constexpr noexcept] bool operator== (const QQuaternion & q1 , const QQuaternion & q2 )

返回 true if q1 等于 q2 ;否则返回 false 。此运算符使用精确浮点比较。

QDataStream & operator>> ( QDataStream & stream , QQuaternion & quaternion )

读取四元数从给定 stream 进给定 quaternion 并返回流引用。

另请参阅 序列化 Qt 数据类型 .