Тип vector3d QML
Тип vector3d относится к значению с атрибутами x, y, и z.
Для создания значения vector3d, укажите его как строку "x,y,z":
Rotation { angle: 60; axis: "0,1,0" } или с помощью функции Qt.vector3d():
Rotation { angle: 60; axis: Qt.vector3d(0, 1, 0) } или как отдельные компоненты x, y, и z:
Rotation { angle: 60; axis.x: 0; axis.y: 1; axis.z: 0 } Каждый атрибут значения vector3d хранится внутри как число с плавающей точкой одинарной точности (float).
При интеграции с C++, обратите внимание, что любое значение QVector3D переданное в QML из C++ автоматически преобразуется в значение 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) | Возвращает результат преобразования this vector3d с 4x4 matrix матрицей, применяемой после вектора |
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 |
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 |
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 |
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 |
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) | Возвращает true, если this vector3d приблизительно равен other vector3d. Приближение будет истинным, если каждый атрибут this находится в пределах epsilon от other. Обратите внимание, что 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.
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-5.15/qml-vector3d.html