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

QVector3D Class

TheQVector3D class represents a vector or vertex in 3D space.More...

Header:#include <QVector3D>
Since: Qt 4.6

Public Functions

QVector3D()
QVector3D(qreal xpos, qreal ypos, qreal zpos)
QVector3D(const QPoint & point)
QVector3D(const QPointF & point)
QVector3D(const QVector2D & vector)
QVector3D(const QVector2D & vector, qreal zpos)
QVector3D(const QVector4D & vector)
qrealdistanceToLine(const QVector3D & point, const QVector3D & direction) const
qrealdistanceToPlane(const QVector3D & plane, const QVector3D & normal) const
qrealdistanceToPlane(const QVector3D & plane1, const QVector3D & plane2, const QVector3D & plane3) const
boolisNull() const
qreallength() const
qreallengthSquared() const
voidnormalize()
QVector3Dnormalized() const
voidsetX(qreal x)
voidsetY(qreal y)
voidsetZ(qreal z)
QPointtoPoint() const
QPointFtoPointF() const
QVector2DtoVector2D() const
QVector4DtoVector4D() const
qrealx() const
qrealy() const
qrealz() const
operator QVariant() const
QVector3D &operator*=(qreal factor)
QVector3D &operator*=(const QVector3D & vector)
QVector3D &operator+=(const QVector3D & vector)
QVector3D &operator-=(const QVector3D & vector)
QVector3D &operator/=(qreal divisor)

Static Public Members

QVector3DcrossProduct(const QVector3D & v1, const QVector3D & v2)
qrealdotProduct(const QVector3D & v1, const QVector3D & v2)
QVector3Dnormal(const QVector3D & v1, const QVector3D & v2)
QVector3Dnormal(const QVector3D & v1, const QVector3D & v2, const QVector3D & v3)

Related Non-Members

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

Detailed Description

TheQVector3D class represents a vector or vertex in 3D space.

Vectors are one of the main building blocks of 3D representation and drawing. They consist of three coordinates, traditionally called x, y, and z.

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

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

See alsoQVector2D,QVector4D, andQQuaternion.

Member Function Documentation

QVector3D::QVector3D()

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

QVector3D::QVector3D(qreal xpos,qreal ypos,qreal zpos)

Constructs a vector with coordinates (xpos,ypos,zpos).

QVector3D::QVector3D(constQPoint & point)

Constructs a vector with x and y coordinates from a 2Dpoint, and a z coordinate of 0.

QVector3D::QVector3D(constQPointF & point)

Constructs a vector with x and y coordinates from a 2Dpoint, and a z coordinate of 0.

QVector3D::QVector3D(constQVector2D & vector)

Constructs a 3D vector from the specified 2Dvector. The z coordinate is set to zero.

See alsotoVector2D().

QVector3D::QVector3D(constQVector2D & vector,qreal zpos)

Constructs a 3D vector from the specified 2Dvector. The z coordinate is set tozpos.

See alsotoVector2D().

QVector3D::QVector3D(constQVector4D & vector)

Constructs a 3D vector from the specified 4Dvector. The w coordinate is dropped.

See alsotoVector4D().

[static]QVector3D QVector3D::crossProduct(constQVector3D & v1, constQVector3D & v2)

Returns the cross-product of vectorsv1 andv2, which corresponds to the normal vector of a plane defined byv1 andv2.

See alsonormal().

qreal QVector3D::distanceToLine(constQVector3D & point, constQVector3D & direction) const

Returns the distance that this vertex is from a line defined bypoint and the unit vectordirection.

Ifdirection is a null vector, then it does not define a line. In that case, the distance frompoint to this vertex is returned.

See alsodistanceToPlane().

qreal QVector3D::distanceToPlane(constQVector3D & plane, constQVector3D & normal) const

Returns the distance from this vertex to a plane defined by the vertexplane and anormal unit vector. Thenormal parameter is assumed to have been normalized to a unit vector.

The return value will be negative if the vertex is below the plane, or zero if it is on the plane.

See alsonormal() anddistanceToLine().

qreal QVector3D::distanceToPlane(constQVector3D & plane1, constQVector3D & plane2, constQVector3D & plane3) const

This is an overloaded function.

Returns the distance from this vertex a plane defined by the verticesplane1,plane2 andplane3.

The return value will be negative if the vertex is below the plane, or zero if it is on the plane.

The two vectors that define the plane areplane2 -plane1 andplane3 -plane1.

See alsonormal() anddistanceToLine().

[static]qreal QVector3D::dotProduct(constQVector3D & v1, constQVector3D & v2)

Returns the dot product ofv1 andv2.

bool QVector3D::isNull() const

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

qreal QVector3D::length() const

Returns the length of the vector from the origin.

See alsolengthSquared() andnormalized().

qreal QVector3D::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().

[static]QVector3D QVector3D::normal(constQVector3D & v1, constQVector3D & v2)

Returns the normal vector of a plane defined by vectorsv1 andv2, normalized to be a unit vector.

UsecrossProduct() to compute the cross-product ofv1 andv2 if you do not need the result to be normalized to a unit vector.

See alsocrossProduct() anddistanceToPlane().

[static]QVector3D QVector3D::normal(constQVector3D & v1, constQVector3D & v2, constQVector3D & v3)

This is an overloaded function.

Returns the normal vector of a plane defined by vectorsv2 -v1 andv3 -v1, normalized to be a unit vector.

UsecrossProduct() to compute the cross-product ofv2 -v1 andv3 -v1 if you do not need the result to be normalized to a unit vector.

See alsocrossProduct() anddistanceToPlane().

void QVector3D::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().

QVector3D QVector3D::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 QVector3D::setX(qreal x)

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

See alsox(),setY(), andsetZ().

void QVector3D::setY(qreal y)

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

See alsoy(),setX(), andsetZ().

void QVector3D::setZ(qreal z)

Sets the z coordinate of this point to the givenz coordinate.

See alsoz(),setX(), andsetY().

QPoint QVector3D::toPoint() const

Returns theQPoint form of this 3D vector. The z coordinate is dropped.

See alsotoPointF() andtoVector2D().

QPointF QVector3D::toPointF() const

Returns theQPointF form of this 3D vector. The z coordinate is dropped.

See alsotoPoint() andtoVector2D().

QVector2D QVector3D::toVector2D() const

Returns the 2D vector form of this 3D vector, dropping the z coordinate.

See alsotoVector4D() andtoPoint().

QVector4D QVector3D::toVector4D() const

Returns the 4D form of this 3D vector, with the w coordinate set to zero.

See alsotoVector2D() andtoPoint().

qreal QVector3D::x() const

Returns the x coordinate of this point.

See alsosetX(),y(), andz().

qreal QVector3D::y() const

Returns the y coordinate of this point.

See alsosetY(),x(), andz().

qreal QVector3D::z() const

Returns the z coordinate of this point.

See alsosetZ(),x(), andy().

QVector3D::operator QVariant() const

Returns the 3D vector as aQVariant.

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

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

See alsooperator/=().

QVector3D & QVector3D::operator*=(constQVector3D & vector)

This is an overloaded function.

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

Note: this is not the same as thecrossProduct() of this vector andvector.

See alsocrossProduct().

QVector3D & QVector3D::operator+=(constQVector3D & vector)

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

See alsooperator-=().

QVector3D & QVector3D::operator-=(constQVector3D & vector)

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

See alsooperator+=().

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

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

See alsooperator*=().

Related Non-Members

boolqFuzzyCompare(constQVector3D & v1, constQVector3D & v2)

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

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

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

constQVector3Doperator*(qreal factor, constQVector3D & vector)

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

See alsoQVector3D::operator*=().

constQVector3Doperator*(constQVector3D & vector,qreal factor)

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

See alsoQVector3D::operator*=().

constQVector3Doperator*(constQVector3D & v1, constQVector3D & v2)

Multiplies the components ofv1 by the corresponding components inv2.

Note: this is not the same as the crossProduct() ofv1 andv2.

See alsoQVector3D::crossProduct().

constQVector3Doperator+(constQVector3D & v1, constQVector3D & v2)

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

See alsoQVector3D::operator+=().

constQVector3Doperator-(constQVector3D & v1, constQVector3D & v2)

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

See alsoQVector3D::operator-=().

constQVector3Doperator-(constQVector3D & vector)

This is an overloaded function.

Returns aQVector3D object that is formed by changing the sign of all three components of the givenvector.

Equivalent toQVector3D(0,0,0) - vector.

constQVector3Doperator/(constQVector3D & vector,qreal divisor)

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

See alsoQVector3D::operator/=().

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

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

See alsoSerializing Qt Data Types.

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

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

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

Reads a 3D 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