QVector2D Class
The QVector2D class represents a vector or vertex in 2D space. More...
Header: | #include <QVector2D> |
qmake: | QT += gui |
Since: | Qt 4.6 |
This class was introduced in Qt 4.6.
Public Functions
QVector2D(const QVector4D &vector) | |
QVector2D(const QVector3D &vector) | |
float | distanceToLine(const QVector2D &point, const QVector2D &direction) const |
float | distanceToPoint(const QVector2D &point) const |
float | length() const |
float | lengthSquared() const |
void | normalize() |
QVector2D | normalized() const |
QVector3D | toVector3D() const |
QVector4D | toVector4D() const |
QVariant | operator QVariant() const |
Static Public Members
float | dotProduct(const QVector2D &v1, const QVector2D &v2) |
Detailed Description
The QVector2D class can also be used to represent vertices in 2D space. We therefore do not need to provide a separate vertex class.
See also QVector3D, QVector4D, and QQuaternion.
Member Function Documentation
QVector2D::QVector2D(const QVector4D &vector)
Constructs a vector with x and y coordinates from a 3D vector. The z and w coordinates of vector are dropped.
See also toVector4D().
QVector2D::QVector2D(const QVector3D &vector)
Constructs a vector with x and y coordinates from a 3D vector. The z coordinate of vector is dropped.
See also toVector3D().
float QVector2D::distanceToLine(const QVector2D &point, const QVector2D &direction) const
Returns the distance that this vertex is from a line defined by point and the unit vector direction.
If direction is a null vector, then it does not define a line. In that case, the distance from point to this vertex is returned.
This function was introduced in Qt 5.1.
See also distanceToPoint().
float QVector2D::distanceToPoint(const QVector2D &point) const
Returns the distance from this vertex to a point defined by the vertex point.
This function was introduced in Qt 5.1.
See also distanceToLine().
[static]
float QVector2D::dotProduct(const QVector2D &v1, const QVector2D &v2)
Returns the dot product of v1 and v2.
float QVector2D::length() const
Returns the length of the vector from the origin.
See also lengthSquared() and normalized().
float QVector2D::lengthSquared() const
Returns the squared length of the vector from the origin. This is equivalent to the dot product of the vector with itself.
See also length() and dotProduct().
void QVector2D::normalize()
Normalizes the currect vector in place. Nothing happens if this vector is a null vector or the length of the vector is very close to 1.
See also length() and normalized().
QVector2D QVector2D::normalized() const
Returns the normalized unit vector form of this vector.
If this vector is null, then a null vector is returned. If the length of the vector is very close to 1, then the vector will be returned as-is. Otherwise the normalized form of the vector of length 1 will be returned.
See also length() and normalize().
QVector3D QVector2D::toVector3D() const
Returns the 3D form of this 2D vector, with the z coordinate set to zero.
See also toVector4D() and toPoint().
QVector4D QVector2D::toVector4D() const
Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
See also toVector3D() and toPoint().
QVariant QVector2D::operator QVariant() const
Returns the 2D vector as a QVariant.