Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QVector2D Class

TheQVector2D class represents a vector or vertex in 2D space.More...

Header:#include <QVector2D>
Since: Qt 4.6

Public Functions

QVector2D()
QVector2D(qreal xpos, qreal ypos)
QVector2D(const QPoint & point)
QVector2D(const QPointF & point)
QVector2D(const QVector3D & vector)
QVector2D(const QVector4D & vector)
boolisNull() const
qreallength() const
qreallengthSquared() const
voidnormalize()
QVector2Dnormalized() const
voidsetX(qreal x)
voidsetY(qreal y)
QPointtoPoint() const
QPointFtoPointF() const
QVector3DtoVector3D() const
QVector4DtoVector4D() const
qrealx() const
qrealy() const
operator QVariant() const
QVector2D &operator*=(qreal factor)
QVector2D &operator*=(const QVector2D & vector)
QVector2D &operator+=(const QVector2D & vector)
QVector2D &operator-=(const QVector2D & vector)
QVector2D &operator/=(qreal divisor)

Static Public Members

qrealdotProduct(const QVector2D & v1, const QVector2D & v2)

Related Non-Members

boolqFuzzyCompare(const QVector2D & v1, const QVector2D & v2)
booloperator!=(const QVector2D & v1, const QVector2D & v2)
const QVector2Doperator*(qreal factor, const QVector2D & vector)
const QVector2Doperator*(const QVector2D & vector, qreal factor)
const QVector2Doperator*(const QVector2D & v1, const QVector2D & v2)
const QVector2Doperator+(const QVector2D & v1, const QVector2D & v2)
const QVector2Doperator-(const QVector2D & v1, const QVector2D & v2)
const QVector2Doperator-(const QVector2D & vector)
const QVector2Doperator/(const QVector2D & vector, qreal divisor)
QDataStream &operator<<(QDataStream & stream, const QVector2D & vector)
booloperator==(const QVector2D & v1, const QVector2D & v2)
QDataStream &operator>>(QDataStream & stream, QVector2D & vector)

Detailed Description

TheQVector2D class represents a vector or vertex in 2D space.

TheQVector2D class can also be used to represent vertices in 2D space. We therefore do not need to provide a separate vertex class.

Note: By design values in theQVector2D instance are stored asfloat. This means that on platforms where theqreal arguments toQVector2D functions are represented bydouble values, it is possible to lose precision.

See alsoQVector3D,QVector4D, andQQuaternion.

Member Function Documentation

QVector2D::QVector2D()

Constructs a null vector, i.e. with coordinates (0, 0, 0).

QVector2D::QVector2D(qreal xpos,qreal ypos)

Constructs a vector with coordinates (xpos,ypos).

QVector2D::QVector2D(constQPoint & point)

Constructs a vector with x and y coordinates from a 2Dpoint.

QVector2D::QVector2D(constQPointF & point)

Constructs a vector with x and y coordinates from a 2Dpoint.

QVector2D::QVector2D(constQVector3D & vector)

Constructs a vector with x and y coordinates from a 3Dvector. The z coordinate ofvector is dropped.

See alsotoVector3D().

QVector2D::QVector2D(constQVector4D & vector)

Constructs a vector with x and y coordinates from a 3Dvector. The z and w coordinates ofvector are dropped.

See alsotoVector4D().

[static]qreal QVector2D::dotProduct(constQVector2D & v1, constQVector2D & v2)

Returns the dot product ofv1 andv2.

bool QVector2D::isNull() const

Returns true if the x and y coordinates are set to 0.0, otherwise returns false.

qreal QVector2D::length() const

Returns the length of the vector from the origin.

See alsolengthSquared() andnormalized().

qreal 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 alsolength() anddotProduct().

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 alsolength() andnormalized().

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 alsolength() andnormalize().

void QVector2D::setX(qreal x)

Sets the x coordinate of this point to the givenx coordinate.

See alsox() andsetY().

void QVector2D::setY(qreal y)

Sets the y coordinate of this point to the giveny coordinate.

See alsoy() andsetX().

QPoint QVector2D::toPoint() const

Returns theQPoint form of this 2D vector.

See alsotoPointF() andtoVector3D().

QPointF QVector2D::toPointF() const

Returns theQPointF form of this 2D vector.

See alsotoPoint() andtoVector3D().

QVector3D QVector2D::toVector3D() const

Returns the 3D form of this 2D vector, with the z coordinate set to zero.

See alsotoVector4D() andtoPoint().

QVector4D QVector2D::toVector4D() const

Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.

See alsotoVector3D() andtoPoint().

qreal QVector2D::x() const

Returns the x coordinate of this point.

See alsosetX() andy().

qreal QVector2D::y() const

Returns the y coordinate of this point.

See alsosetY() andx().

QVector2D::operator QVariant() const

Returns the 2D vector as aQVariant.

QVector2D & QVector2D::operator*=(qreal factor)

Multiplies this vector's coordinates by the givenfactor, and returns a reference to this vector.

See alsooperator/=().

QVector2D & QVector2D::operator*=(constQVector2D & vector)

Multiplies the components of this vector by the corresponding components invector.

QVector2D & QVector2D::operator+=(constQVector2D & vector)

Adds the givenvector to this vector and returns a reference to this vector.

See alsooperator-=().

QVector2D & QVector2D::operator-=(constQVector2D & vector)

Subtracts the givenvector from this vector and returns a reference to this vector.

See alsooperator+=().

QVector2D & QVector2D::operator/=(qreal divisor)

Divides this vector's coordinates by the givendivisor, and returns a reference to this vector.

See alsooperator*=().

Related Non-Members

boolqFuzzyCompare(constQVector2D & v1, constQVector2D & v2)

Returns true ifv1 andv2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.

booloperator!=(constQVector2D & v1, constQVector2D & v2)

Returns true ifv1 is not equal tov2; otherwise returns false. This operator uses an exact floating-point comparison.

constQVector2Doperator*(qreal factor, constQVector2D & vector)

Returns a copy of the givenvector, multiplied by the givenfactor.

See alsoQVector2D::operator*=().

constQVector2Doperator*(constQVector2D & vector,qreal factor)

Returns a copy of the givenvector, multiplied by the givenfactor.

See alsoQVector2D::operator*=().

constQVector2Doperator*(constQVector2D & v1, constQVector2D & v2)

Multiplies the components ofv1 by the corresponding components inv2.

constQVector2Doperator+(constQVector2D & v1, constQVector2D & v2)

Returns aQVector2D object that is the sum of the given vectors,v1 andv2; each component is added separately.

See alsoQVector2D::operator+=().

constQVector2Doperator-(constQVector2D & v1, constQVector2D & v2)

Returns aQVector2D object that is formed by subtractingv2 fromv1; each component is subtracted separately.

See alsoQVector2D::operator-=().

constQVector2Doperator-(constQVector2D & vector)

This is an overloaded function.

Returns aQVector2D object that is formed by changing the sign of the components of the givenvector.

Equivalent toQVector2D(0,0) - vector.

constQVector2Doperator/(constQVector2D & vector,qreal divisor)

Returns theQVector2D object formed by dividing all three components of the givenvector by the givendivisor.

See alsoQVector2D::operator/=().

QDataStream &operator<<(QDataStream & stream, constQVector2D & vector)

Writes the givenvector to the givenstream and returns a reference to the stream.

See alsoSerializing Qt Data Types.

booloperator==(constQVector2D & v1, constQVector2D & v2)

Returns true ifv1 is equal tov2; otherwise returns false. This operator uses an exact floating-point comparison.

QDataStream &operator>>(QDataStream & stream,QVector2D & vector)

Reads a 2D vector from the givenstream into the givenvector and returns a reference to the stream.

See alsoSerializing Qt Data Types.

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp