quaternion QML Value Type

A quaternion type has scalar, x, y, and z attributes. 更多...

详细描述

A quaternion type has scalar , x , y and z 属性。

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:

函数签名 描述 范例
real dotProduct(quaternion other) Returns the scalar real result of the dot product of this quaternion with the other quaternion
var a = Qt.quaternion(1,2,3,4);
var b

=



Qt



.

quaternion(

5


,


6


,


7


,


8

);
var c

=

a

.

dotProduct(b);
console

.

log(c);

// 70

								
quaternion times(quaternion other) Returns the quaternion result of multiplying this quaternion with the other quaternion, which corresponds to applying both of the rotations
var a = Qt.quaternion(1 / Math.sqrt(2), 1 / Math.sqrt(2), 0, 0);
var b

=



Qt



.

quaternion(

1


/

Math

.

sqrt(

2

)

,


0


,


1


/

Math

.

sqrt(

2

)

,


0

);
var c

=

b

.

times(a);
console

.

log(c

.

toString());

// QQuaternion(0.5, 0.5, 0.5, -0.5)

								
vector3d times(vector3d vector) Returns the vector3d result of rotating the vector with this quaternion
var a = Qt.quaternion(0.5,0.5,0.5,-0.5);
var b

=



Qt



.

vector3d(

4


,


5


,


6

);
var c

=

a

.

times(b);
console

.

log(c

.

toString());

// QVector3D(5, -6, -4)

								
quaternion times(real factor) Returns the quaternion result of multiplying this quaternion with the scalar factor
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 this quaternion with the other quaternion
var a = Qt.quaternion(1,2,3,4);
var b

=



Qt



.

quaternion(

5


,


6


,


7


,


8

);
var c

=

a

.

plus(b);
console

.

log(c

.

toString());

// QQuaternion(6, 8, 10, 12)

								
quaternion minus(quaternion other) Returns the quaternion result of the subtraction of other quaternion from this quaternion
var a = Qt.quaternion(1,2,3,4);
var b

=



Qt



.

quaternion(

5


,


6


,


7


,


8

);
var c

=

a

.

minus(b);
console

.

log(c

.

toString());

// QQuaternion(-4, -4, -4, -4)

								
quaternion normalized() Returns the normalized unit form of this quaternion
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 this quaternion
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 this quaternion
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 this quaternion
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 this quaternion
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 this quaternion 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) 返回 true 若 this quaternion is approximately equal to the other quaternion. The approximation will be true if each attribute of this is within epsilon of other 。注意, epsilon is an optional argument, the default epsilon is 0.00001.
var a = Qt.quaternion(1,2,3,4);
var b

=



Qt



.

quaternion(

1.0001


,


1.9998


,


2.0001


,


3.9999

);
var c

=

a

.

fuzzyEquals(b);

// default epsilon

var d

=

a

.

fuzzyEquals(b

,


0.005

);

// supplied epsilon

console

.

log(c

+


" "


+

d);

// false true

								

Properties of type quaternion have Qt.quaternion(1, 0, 0, 0) as their default value.

This value type is provided by the QtQuick 导入。

另请参阅 QML Value Types .