En esta página

vector2d QML Value Type

Un tipo vector2d tiene atributos x e y. Más...

Descripción detallada

Un tipo vector2d tiene atributos x y y, por lo demás es similar al tipo vector3d.

Las propiedades de tipo vector2d tienen un vector cero como valor por defecto. Esto tiene tanto x como y establecidos en 0.

Consulte la documentación sobre el tipo vector3d para obtener más información.

Para crear un valor vector2d, especifíquelo como una cadena "x,y", o defina los componentes individualmente, o compóngalo con la función Qt.vector2d().

El tipo vector2d tiene las siguientes funciones idempotentes que pueden invocarse en QML:

Función FirmaDescripciónEjemplo
real dotProduct(vector2d otro)Devuelve el resultado real escalar del producto punto de this vector2d con el other vector2d
var a = Qt.vector2d(1,2);
var b = Qt.vector2d(3,4);
var c = a.dotProduct(b);
console.log(c); // 11
vector2d veces(vector2d otro)Devuelve el resultado vector2d de multiplicar this vector2d por other 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 veces(factor real)Devuelve el resultado vector2d de multiplicar this vector2d por el escalar 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 otro)Devuelve el vector2d resultado de la suma de this vector2d con el other 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 menos(vector2d otro)Devuelve el resultado vector2d de la resta de other vector2d de this 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 normalizado()Devuelve la forma normalizada del vector this
var a = Qt.vector2d(1,2);
var b = a.normalized();
console.log(b.toString()); // QVector2D(0.447214, 0.894427)
longitud real()Devuelve el valor real escalar de la longitud de this vector2d
var a = Qt.vector2d(1,2);
var b = a.length();
console.log(b.toString()); // 2.23606797749979
vector3d toVector3d()Devuelve el vector3d resultante de convertir this vector2d en un vector3d
var a = Qt.vector2d(1,2);
var b = a.toVector3d();
console.log(b.toString()); // QVector3D(1, 2, 0)
vector4d toVector4d()Devuelve el vector4d resultante de convertir this vector2d en un vector4d
var a = Qt.vector2d(1,2);
var b = a.toVector4d();
console.log(b.toString()); // QVector4D(1, 2, 0, 0)
bool fuzzyEquals(vector2d otro, real epsilon)Devuelve true si this vector2d es aproximadamente igual a other vector2d. La aproximación será verdadera si cada atributo de this está dentro de epsilon de other. Tenga en cuenta que epsilon es un argumento opcional, el valor por defecto epsilon es 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

Este tipo de valor es proporcionado por la importación QtQuick.

Véase también Tipos de valor 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.