本页内容

vector4d QML Value Type

vector4d 类型具有 x、y、z 和 w 属性。更多内容...

Import Statement: import QtQuick

详细说明

vector4d 类型具有x 、y 、z 和w 属性,除此之外,它与vector3d 类型相似。

vector4d 类型的属性默认具有零向量。此时,x 、y 、z 和w 均设置为0 。

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

要创建一个vector4d 值,可以将其指定为“x,y,z,w”字符串,或者单独定义各分量,或者使用 Qt.vector4d() 函数进行组合。

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

函数签名描述示例
real dotProduct(vector4d other)返回向量this 与向量other 的点积结果,结果为实数标量
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)返回将this 向量4d与4x4矩阵matrix 进行变换后得到的向量4d结果,该矩阵在向量之后应用
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 向量4d与other 向量4d相乘后得到的向量4d结果
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结果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 向量4d与other 向量4d相加所得的向量4d结果
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 向量3D的长度,该长度为标量实数值
var a = Qt.vector4d(1,2,3,4);
var b = a.length();
console.log(b.toString()); // 5.477225575051661
vector2d toVector2d()返回将this 向量4D转换为向量2D后的结果
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)other如果this 的vector4d与other 的vector4d近似相等,则返回true。当this 的每个属性值都在epsilon 范围内时,该近似关系成立。请注意,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 值类型。

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