vector2d QML Value Type

vector2d 类型具有 x 和 y 属性。更多

详细说明

vector2d 类型具有xy 属性,否则与vector3d 类型类似。

vector2d 类型的属性默认值为零向量。xy 都设置为0

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

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

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

函数签名说明示例
real dotProduct(vector2d other)返回this vector2d 与other vector2d 的点积的标量实数结果。
var a = Qt.vector2d(1,2);
var b = Qt.vector2d(3,4);
var c = a.dotProduct(b);
console.log(c); // 11
vector2d times(vector2d other)返回this vector2d 与other vector2d 相乘的 vector2d 结果。
var a = Qt.vector2d(1,2);
var b = Qt.vector2d(3,4);
var c = a.times(b);
console.log(c.toString()); // QVector2D(3, 8)
vector2d times(real factor)返回this vector2d 与标量相乘的 vector2d 结果factor
var a = Qt.vector2d(1,2);
var b = 4.48;
var c = a.times(b);
console.log(c.toString()); // QVector2D(4.48, 8.96)
vector2d plus(vector2d other)返回this vector2d 与other vector2d 相加的 vector2d 结果
var a = Qt.vector2d(1,2);
var b = Qt.vector2d(3,4);
var c = a.plus(b);
console.log(c.toString()); // QVector2D(4, 6)
vector2d minus(vector2d other)返回other vector2d 与this vector2d 相减的 vector2d 结果
var a = Qt.vector2d(1,2);
var b = Qt.vector2d(3,4);
var c = a.minus(b);
console.log(c.toString()); // QVector2D(-2, -2)
vector2d normalized()返回this 向量的归一化形式
var a = Qt.vector2d(1,2);
var b = a.normalized();
console.log(b.toString()); // QVector2D(0.447214, 0.894427)
real length()返回this vector2d 长度的标量实值
var a = Qt.vector2d(1,2);
var b = a.length();
console.log(b.toString()); // 2.23606797749979
vector3d toVector3d()返回this vector2d 转换为 vector3d 的结果
var a = Qt.vector2d(1,2);
var b = a.toVector3d();
console.log(b.toString()); // QVector3D(1, 2, 0)
vector4d toVector4d()返回将this vector2d 转换为 vector4d 后的 vector4d 结果
var a = Qt.vector2d(1,2);
var b = a.toVector4d();
console.log(b.toString()); // QVector4D(1, 2, 0, 0)
bool fuzzyEquals(vector2d other, real epsilon)如果this vector2d 近似等于other vector2d,则返回 true。如果this 的每个属性都在otherepsilon 范围内,近似值将为真。请注意,epsilon 是一个可选参数,默认epsilon 为 0.00001。
var a = Qt.vector2d(1,2);
var b = Qt.vector2d(1.0001, 1.9998);
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.