quaternion QML Value Type
A quaternion type has scalar, x, y, and z attributes. More...
Detailed Description
A quaternion type has scalar, x, y and z attributes.
To create a quaternion value, specify it as a "scalar,x,y,z" string, or define the components individually, or compose it with the Qt.quaternion() function.
The quaternion type has the following idempotent functions which can be invoked in QML:
| Function Signature | Description | Example | 
|---|---|---|
| real dotProduct(quaternion other) | Returns the scalar real result of the dot product of thisquaternion with theotherquaternion | |
| quaternion times(quaternion other) | Returns the quaternion result of multiplying thisquaternion with theotherquaternion, which corresponds to applying both of the rotations | |
| vector3d times(vector3d vector) | Returns the vector3d result of rotating the vectorwiththisquaternion | |
| quaternion times(real factor) | Returns the quaternion result of multiplying thisquaternion with the scalarfactor | var a = Qt.quaternion(1,2,3,4); var b = 4.48; var c = a.times(b); console.log(c.toString()); // QQuaternion(4.48, 8.96, 13.44, 17.92) | 
| quaternion plus(quaternion other) | Returns the quaternion result of the addition of thisquaternion with theotherquaternion | |
| quaternion minus(quaternion other) | Returns the quaternion result of the subtraction of otherquaternion fromthisquaternion | |
| quaternion normalized() | Returns the normalized unit form of thisquaternion | var a = Qt.quaternion(1,2,3,4); var b = a.normalized(); console.log(b.toString()); // QQuaternion(0.182574, 0.365148, 0.547723, 0.730297) | 
| quaternion inverted() | Returns the inverse of thisquaternion | var a = Qt.quaternion(0.5,0.5,0.5,-0.5); var b = a.inverted(); console.log(b.toString()); // QQuaternion(0.5, -0.5, -0.5, 0.5) | 
| quaternion conjugated() | Returns the conjugate of thisquaternion | var a = Qt.quaternion(1,2,3,4); var b = a.conjugated() console.log(b.toString()); // QQuaternion(1, -2, -3, -4) | 
| real length() | Returns the scalar real value of the length of thisquaternion | var a = Qt.quaternion(1,2,3,4); var b = a.length(); console.log(b.toString()); // 5.477225575051661 | 
| vector3d toEulerAngles() | Returns the vector3d Euler angles (in degrees) that corresponds to thisquaternion | var a = Qt.quaternion(0.933012,0.25,-0.25,0.066987); var b = a.toEulerAngles(); console.log(b.toString()); // QVector3D(30, -30, -4.28846e-05) | 
| vector4d toVector4d() | Returns the vector4d result of converting thisquaternion to a vector4d | var a = Qt.quaternion(1,2,3,4); var b = a.toVector4d(); console.log(b.toString()); // QVector4D(2, 3, 4, 1) | 
| bool fuzzyEquals(quaternion other, real epsilon) | Returns true if thisquaternion is approximately equal to theotherquaternion. The approximation will be true if each attribute ofthisis withinepsilonofother. Note thatepsilonis an optional argument, the defaultepsilonis 0.00001. | 
Properties of type quaternion have Qt.quaternion(1, 0, 0, 0) as their default value.
This value type is provided by the QtQuick import.
See also QML Value Types.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.
