vector3d QML Value Type

一个具有 x、y 和 z 属性的值。更多

详细说明

vector3d 类型指的是一个具有xyz 属性的值。

vector3d 类型的属性默认为零向量。xyz 设置为0

要创建vector3d 值,请将其指定为 "x,y,z "字符串:

Rotation { angle: 60; axis: "0,1,0" }

或使用Qt.vector3d() 函数:

Rotation { angle: 60; axis: Qt.vector3d(0, 1, 0) }

或作为单独的xyz 组件:

Rotation { angle: 60; axis.x: 0; axis.y: 1; axis.z: 0 }

vector3d 值的每个属性在内部都存储为单精度浮点数 (float)。

与 C++ 集成时,请注意任何从 C++ 传入 QML 的 QVector3D 值都会自动转换为vector3d 值,反之亦然。

vector3d 类型有以下可在 QML 中调用的幂函数:

函数签名说明示例
vector3d crossProduct(vector3d other)返回this vector3d 与other vector3d 的交乘结果。
var a = Qt.vector3d(1,2,3);
var b = Qt.vector3d(4,5,6);
var c = a.crossProduct(b);
console.log(c.toString()); // QVector3D(-3, 6, -3)
real dotProduct(vector3d other)返回this vector3d 与other vector3d 的点积的标量实数结果。
var a = Qt.vector3d(1,2,3);
var b = Qt.vector3d(4,5,6);
var c = a.dotProduct(b);
console.log(c); // 32
vector3d times(matrix4x4 matrix)Returns the vector3d result of transformingthis vector3d with the 4x4matrix with the matrix applied post-vector
var a = Qt.vector3d(1,2,3);
var b = Qt.matrix4x4(4,5,6,7,8,9,10,11,
                     12,13,14,15,16,17,18,19);
var c = a.times(b);
console.log(c.toString());
// QVector3D(0.774194, 0.849462, 0.924731)
vector3d times(vector3d other)返回this vector3d 与other vector3d 相乘的 vector3d 结果
var a = Qt.vector3d(1,2,3);
var b = Qt.vector3d(4,5,6);
var c = a.times(b);
console.log(c.toString()); // QVector3D(4, 10, 18)
vector3d times(real factor)返回this vector3d 与标量相乘的结果。factor
var a = Qt.vector3d(1,2,3);
var b = 4.48;
var c = a.times(b);
console.log(c.toString()); // QVector3D(4.48, 8.96, 13.44)
vector3d plus(vector3d other)返回this vector3d 与other vector3d 相加的 vector3d 结果
var a = Qt.vector3d(1,2,3);
var b = Qt.vector3d(4,5,6);
var c = a.plus(b);
console.log(c.toString()); // QVector3D(5, 7, 9)
vector3d minus(vector3d other)返回other vector3d 与this vector3d 相减的 vector3d 结果
var a = Qt.vector3d(1,2,3);
var b = Qt.vector3d(4,5,6);
var c = a.minus(b);
console.log(c.toString()); // QVector3D(-3, -3, -3)
vector3d normalized()返回this 向量的归一化形式
var a = Qt.vector3d(1,2,3);
var b = a.normalized();
console.log(b.toString());
// QVector3D(0.267261, 0.534522, 0.801784)
real length()返回this vector3d 长度的标量实值
var a = Qt.vector3d(1,2,3);
var b = a.length();
console.log(b.toString()); // 3.7416573867739413
vector2d toVector2d()返回this vector3d 转换为 vector2d 的结果
var a = Qt.vector3d(1,2,3);
var b = a.toVector2d();
console.log(b.toString()); // QVector2D(1, 2)
vector4d toVector4d()返回将this vector3d 转换为 vector4d 的 vector4d 结果
var a = Qt.vector3d(1,2,3);
var b = a.toVector4d();
console.log(b.toString()); // QVector4D(1, 2, 3, 0)
bool fuzzyEquals(vector3d other, real epsilon)如果this vector3d 近似等于other vector3d,则返回 true。如果this 的每个属性都在otherepsilon 范围内,则近似值为真。请注意,epsilon 是一个可选参数,默认epsilon 为 0.00001。
var a = Qt.vector3d(1,2,3);
var b = Qt.vector3d(1.0001, 1.9998, 2.0001);
var c = a.fuzzyEquals(b);        // default epsilon
var d = a.fuzzyEquals(b, 0.005); // supplied epsilon
console.log(c + " " + d); // false true

该值类型由QtQuick 导入提供。

另请参阅 QML 值类型

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