vector4d QML Value Type

向量 4d 类型具有 x、y、z 和 w 属性。更多

详细说明

vector4d 类型具有x,y,zw 属性,否则与vector3d 类型类似。

vector4d 类型的属性默认为零向量。x,y,zw 设置为0

更多信息,请参阅vector3d 类型的相关文档。

要创建vector4d 值,可将其指定为 "x,y,z,w "字符串,或单独定义组件,或使用 Qt.vector4d() 函数组成。

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

函数签名描述示例
real dotProduct(vector4d other)返回this vector4d 与other vector4d 的点积的标量实数结果。
var a = Qt.vector4d(1,2,3,4);
var b = Qt.vector4d(5,6,7,8);
var c = a.dotProduct(b);
console.log(c); // 70
vector4d times(matrix4x4 matrix)Returns the vector4d result of transformingthis vector4d with the 4x4matrix with the matrix applied post-vector
var a = Qt.vector4d(1,2,3,4);
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()); // QVector4D(120, 130, 140, 150)
vector4d times(vector4d other)返回this vector4d 与other vector4d 相乘的 vector4d 结果
var a = Qt.vector4d(1,2,3,4);
var b = Qt.vector4d(5,6,7,8);
var c = a.times(b);
console.log(c.toString()); // QVector4D(5, 12, 21, 32)
vector4d times(real factor)返回this vector4d 与标量相乘的 vector4d 结果factor
var a = Qt.vector4d(1,2,3,4);
var b = 4.48;
var c = a.times(b);
console.log(c.toString()); // QVector3D(4.48, 8.96,
                                        13.44, 17.92)
vector4d plus(vector4d other)返回this vector4d 与other vector4d 相加的 vector4d 结果
var a = Qt.vector4d(1,2,3,4);
var b = Qt.vector4d(5,6,7,8);
var c = a.plus(b);
console.log(c.toString()); // QVector4D(6, 8, 10, 12)
vector4d minus(vector4d other)返回other vector4d 与this vector4d 相减的 vector4d 结果
var a = Qt.vector4d(1,2,3,4);
var b = Qt.vector4d(5,6,7,8);
var c = a.minus(b);
console.log(c.toString()); // QVector4D(-4, -4, -4, -4)
vector4d normalized()返回this 向量的归一化形式
var a = Qt.vector4d(1,2,3,4);
var b = a.normalized();
console.log(b.toString());
// QVector4D(0.182574, 0.365148, 0.547723, 0.730297)
real length()返回this vector3d 长度的标量实值
var a = Qt.vector4d(1,2,3,4);
var b = a.length();
console.log(b.toString()); // 5.477225575051661
vector2d toVector2d()返回this vector4d 转换为 vector2d 的结果
var a = Qt.vector4d(1,2,3,4);
var b = a.toVector2d();
console.log(b.toString()); // QVector2D(1, 2)
vector3d toVector3d()返回将this vector4d 转换为 vector3d 的 vector3d 结果
var a = Qt.vector4d(1,2,3,4);
var b = a.toVector3d();
console.log(b.toString()); // QVector3D(1, 2, 3)
bool fuzzyEquals(vector4d other, real epsilon)如果this vector4d 近似等于other vector4d,则返回 true。如果this 的每个属性都在otherepsilon 范围内,则近似值为真。请注意,epsilon 是一个可选参数,默认epsilon 为 0.00001。
var a = Qt.vector4d(1,2,3,4);
var b = Qt.vector4d(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

该值类型由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.