![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QVector3D class represents a vector or vertex in 3D space. More...
#include <qvectornd.h>
Public Member Functions | |
constexpr | QVector3D () noexcept |
Constructs a null vector, i.e. | |
QVector3D (Qt::Initialization) noexcept | |
constexpr | QVector3D (float xpos, float ypos, float zpos) noexcept |
Constructs a vector with coordinates (xpos, ypos, zpos). | |
constexpr | QVector3D (QPoint point) noexcept |
Constructs a vector with x and y coordinates from a 2D point, and a z coordinate of 0. | |
constexpr | QVector3D (QPointF point) noexcept |
Constructs a vector with x and y coordinates from a 2D point, and a z coordinate of 0. | |
constexpr | QVector3D (QVector2D vector) noexcept |
Constructs a 3D vector from the specified 2D vector. | |
constexpr | QVector3D (QVector2D vector, float zpos) noexcept |
Constructs a 3D vector from the specified 2D vector. | |
constexpr | QVector3D (QVector4D vector) noexcept |
Constructs a 3D vector from the specified 4D vector. | |
constexpr bool | isNull () const noexcept |
Returns true if the x, y, and z coordinates are set to 0.0, otherwise returns false . | |
constexpr float | x () const noexcept |
Returns the x coordinate of this point. | |
constexpr float | y () const noexcept |
Returns the y coordinate of this point. | |
constexpr float | z () const noexcept |
Returns the z coordinate of this point. | |
constexpr void | setX (float x) noexcept |
Sets the x coordinate of this point to the given finite x coordinate. | |
constexpr void | setY (float y) noexcept |
Sets the y coordinate of this point to the given finite y coordinate. | |
constexpr void | setZ (float z) noexcept |
Sets the z coordinate of this point to the given finite z coordinate. | |
constexpr float & | operator[] (int i) |
constexpr float | operator[] (int i) const |
float | length () const noexcept |
Returns the length of the vector from the origin. | |
constexpr float | lengthSquared () const noexcept |
Returns the squared length of the vector from the origin. | |
QVector3D | normalized () const noexcept |
Returns the normalized unit vector form of this vector. | |
void | normalize () noexcept |
Normalizes the current vector in place. | |
constexpr QVector3D & | operator+= (QVector3D vector) noexcept |
Adds the given vector to this vector and returns a reference to this vector. | |
constexpr QVector3D & | operator-= (QVector3D vector) noexcept |
Subtracts the given vector from this vector and returns a reference to this vector. | |
constexpr QVector3D & | operator*= (float factor) noexcept |
Multiplies this vector's coordinates by the given finite factor and returns a reference to this vector. | |
constexpr QVector3D & | operator*= (QVector3D vector) noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Multiplies each component of this vector by the corresponding component in vector and returns a reference to this vector. | |
constexpr QVector3D & | operator/= (float divisor) |
Divides this vector's coordinates by the given divisor, and returns a reference to this vector. | |
constexpr QVector3D & | operator/= (QVector3D vector) |
Q_GUI_EXPORT QVector3D | project (const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const |
Q_GUI_EXPORT QVector3D | unproject (const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport) const |
QT_WARNING_POP float | distanceToPoint (QVector3D point) const noexcept |
constexpr float | distanceToPlane (QVector3D plane, QVector3D normal) const noexcept |
Returns the distance from this vertex to a plane defined by the vertex plane and a normal unit vector. | |
float | distanceToPlane (QVector3D plane1, QVector3D plane2, QVector3D plane3) const noexcept |
Returns the distance from this vertex to a plane defined by the vertices plane1, plane2 and plane3. | |
float | distanceToLine (QVector3D point, QVector3D direction) const noexcept |
Returns the distance that this vertex is from a line defined by point and the unit vector direction. | |
constexpr QVector2D | toVector2D () const noexcept |
Returns the 2D vector form of this 3D vector, dropping the z coordinate. | |
constexpr QVector4D | toVector4D () const noexcept |
Returns the 4D form of this 3D vector, with the w coordinate set to zero. | |
constexpr QPoint | toPoint () const noexcept |
Returns the QPoint form of this 3D vector. | |
constexpr QPointF | toPointF () const noexcept |
Returns the QPointF form of this 3D vector. | |
Q_GUI_EXPORT | operator QVariant () const |
Returns the 3D vector as a QVariant. | |
Static Public Member Functions | |
static constexpr float | dotProduct (QVector3D v1, QVector3D v2) noexcept |
Returns the dot product of v1 and v2. | |
static constexpr QVector3D | crossProduct (QVector3D v1, QVector3D v2) noexcept |
Returns the cross-product of vectors v1 and v2, which is normal to the plane spanned by v1 and v2. | |
static QVector3D | normal (QVector3D v1, QVector3D v2) noexcept |
Returns the unit normal vector of a plane spanned by vectors v1 and v2, which must not be parallel to one another. | |
static QVector3D | normal (QVector3D v1, QVector3D v2, QVector3D v3) noexcept |
Returns the unit normal vector of a plane spanned by vectors v2 - v1 and v3 - v1, which must not be parallel to one another. | |
Friends | |
class | QVector2D |
class | QVector4D |
QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE constexpr friend bool | operator== (QVector3D v1, QVector3D v2) noexcept |
Returns true if v1 is equal to v2; otherwise returns false . | |
constexpr friend bool | operator!= (QVector3D v1, QVector3D v2) noexcept |
Returns true if v1 is not equal to v2; otherwise returns false . | |
constexpr friend QVector3D | operator+ (QVector3D v1, QVector3D v2) noexcept |
//! | |
constexpr friend QVector3D | operator- (QVector3D v1, QVector3D v2) noexcept |
//! | |
constexpr friend QVector3D | operator* (float factor, QVector3D vector) noexcept |
//! | |
constexpr friend QVector3D | operator* (QVector3D vector, float factor) noexcept |
//! | |
constexpr friend QVector3D | operator* (QVector3D v1, QVector3D v2) noexcept |
//! | |
constexpr friend QVector3D | operator- (QVector3D vector) noexcept |
//! | |
constexpr friend QVector3D | operator/ (QVector3D vector, float divisor) |
//! | |
constexpr friend QVector3D | operator/ (QVector3D vector, QVector3D divisor) |
//! | |
Q_GUI_EXPORT bool | qFuzzyCompare (QVector3D v1, QVector3D v2) |
//! | |
QVector3D | operator* (const QVector3D &vector, const QMatrix4x4 &matrix) |
QVector3D | operator* (const QMatrix4x4 &matrix, const QVector3D &vector) |
template<std::size_t I, typename V, std::enable_if_t<(I< 3), bool > = true, std::enable_if_t< std::is_same_v< q20::remove_cvref_t< V >, QVector3D >, bool > = true> | |
constexpr decltype(auto) | get (V &&vec) noexcept |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &stream, QVector3D vector) |
Writes the given vector to the given stream and returns a reference to the stream. | |
QDataStream & | operator>> (QDataStream &stream, QVector3D &vector) |
Reads a 3D vector from the given stream into the given vector and returns a reference to the stream. | |
The QVector3D class represents a vector or vertex in 3D space.
\inmodule QtGui
Vectors are one of the main building blocks of 3D representation and drawing. They consist of three finite floating-point coordinates, traditionally called x, y, and z.
The QVector3D class can also be used to represent vertices in 3D space. We therefore do not need to provide a separate vertex class.
Definition at line 170 of file qvectornd.h.
|
inlineconstexprnoexcept |
Constructs a null vector, i.e.
with coordinates (0, 0, 0).
Definition at line 650 of file qvectornd.h.
Referenced by normalized(), and QVector4D::toVector3DAffine().
|
inlineexplicitnoexcept |
Constructs a vector without initializing the contents.
Definition at line 174 of file qvectornd.h.
|
inlineconstexprnoexcept |
Constructs a vector with coordinates (xpos, ypos, zpos).
All parameters must be finite.
Definition at line 175 of file qvectornd.h.
|
inlineexplicitconstexprnoexcept |
Constructs a vector with x and y coordinates from a 2D point, and a z coordinate of 0.
Definition at line 652 of file qvectornd.h.
|
inlineexplicitconstexprnoexcept |
Constructs a vector with x and y coordinates from a 2D point, and a z coordinate of 0.
Definition at line 654 of file qvectornd.h.
|
inlineexplicitconstexprnoexcept |
Constructs a 3D vector from the specified 2D vector.
The z coordinate is set to zero.
Definition at line 657 of file qvectornd.h.
References QVector2D::operator[]().
|
inlineconstexprnoexcept |
Constructs a 3D vector from the specified 2D vector.
The z coordinate is set to zpos, which must be finite.
Definition at line 658 of file qvectornd.h.
References QVector2D::operator[]().
|
inlineexplicitconstexprnoexcept |
Constructs a 3D vector from the specified 4D vector.
The w coordinate is dropped.
Definition at line 662 of file qvectornd.h.
References QVector4D::operator[]().
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.
Definition at line 808 of file qvectornd.h.
References dotProduct(), isNull(), length(), operator*, operator+, and operator-.
|
inlineconstexprnoexcept |
Returns the distance from this vertex to a plane defined by the vertex plane and a normal unit vector.
The normal 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.
Definition at line 797 of file qvectornd.h.
References dotProduct(), and operator-.
|
inlinenoexcept |
Returns the distance from this vertex to a plane defined by the vertices plane1, plane2 and plane3.
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 are plane2 - plane1 and plane3 - plane1.
Definition at line 802 of file qvectornd.h.
References dotProduct(), normal(), and operator-.
|
inlinenoexcept |
Returns the distance from this vertex to a point defined by the vertex point.
Definition at line 792 of file qvectornd.h.
References length(), and operator-.
Returns the dot product of v1 and v2.
Definition at line 770 of file qvectornd.h.
Referenced by distanceToLine(), distanceToPlane(), and distanceToPlane().
|
inlineconstexprnoexcept |
Returns true
if the x, y, and z coordinates are set to 0.0, otherwise returns false
.
Definition at line 665 of file qvectornd.h.
Referenced by distanceToLine().
|
inlinenodiscardnoexcept |
Returns the length of the vector from the origin.
Definition at line 690 of file qvectornd.h.
Referenced by distanceToLine(), distanceToPoint(), normalize(), and normalized().
|
inlinenodiscardconstexprnoexcept |
Returns the squared length of the vector from the origin.
This is equivalent to the dot product of the vector with itself.
Definition at line 713 of file qvectornd.h.
Returns the unit normal vector of a plane spanned by vectors v1 and v2, which must not be parallel to one another.
Use crossProduct() to compute the cross-product of v1 and v2 if you do not need the result to be normalized to a unit vector.
Definition at line 782 of file qvectornd.h.
References crossProduct(), and normalized().
Referenced by distanceToPlane().
|
inlinestaticnodiscardnoexcept |
Returns the unit normal vector of a plane spanned by vectors v2 - v1 and v3 - v1, which must not be parallel to one another.
Use crossProduct() to compute the cross-product of v2 - v1 and v3 - v1 if you do not need the result to be normalized to a unit vector.
Definition at line 787 of file qvectornd.h.
References crossProduct(), normalized(), and operator-.
|
inlinenoexcept |
Normalizes the current vector in place.
Nothing happens if this vector is a null vector or the length of the vector is very close to 1.
Definition at line 702 of file qvectornd.h.
References length().
|
inlinenodiscardnoexcept |
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.
Definition at line 695 of file qvectornd.h.
References QVector3D(), and length().
Referenced by normal(), and normal().
QVector3D::operator QVariant | ( | ) | const |
Returns the 3D vector as a QVariant.
Definition at line 1033 of file qvectornd.cpp.
|
inlineconstexprnoexcept |
Multiplies this vector's coordinates by the given finite factor and returns a reference to this vector.
Definition at line 734 of file qvectornd.h.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Multiplies each component of this vector by the corresponding component in vector and returns a reference to this vector.
Note: this is not the same as the crossProduct() of this vector and vector. (Its components add up to the dot product of this vector and vector.)
Definition at line 742 of file qvectornd.h.
Adds the given vector to this vector and returns a reference to this vector.
Definition at line 718 of file qvectornd.h.
Subtracts the given vector from this vector and returns a reference to this vector.
Definition at line 726 of file qvectornd.h.
|
inlineconstexpr |
Divides this vector's coordinates by the given divisor, and returns a reference to this vector.
The divisor must not be either zero or NaN.
Definition at line 750 of file qvectornd.h.
Divides each component of this vector by the corresponding component in vector and returns a reference to this vector.
The vector must have no component that is either zero or NaN.
Definition at line 759 of file qvectornd.h.
|
inlineconstexpr |
Returns the component of the vector at index position i as a modifiable reference.
i must be a valid index position in the vector (i.e., 0 <= i < 3).
Definition at line 678 of file qvectornd.h.
Referenced by QVector2D::QVector2D(), QVector4D::QVector4D(), and QVector4D::QVector4D().
|
inlineconstexpr |
Returns the component of the vector at index position i.
i must be a valid index position in the vector (i.e., 0 <= i < 3).
Definition at line 684 of file qvectornd.h.
QVector3D QVector3D::project | ( | const QMatrix4x4 & | modelView, |
const QMatrix4x4 & | projection, | ||
const QRect & | viewport ) const |
Returns the window coordinates of this vector initially in object/model coordinates using the model view matrix modelView, the projection matrix projection and the viewport dimensions viewport.
When transforming from clip to normalized space, a division by the w component on the vector components takes place. To prevent dividing by 0 if w equals to 0, it is set to 1.
Definition at line 784 of file qvectornd.cpp.
References QVector4D::QVector4D(), QVector4D::operator/=(), QVector4D::setW(), QVector4D::setX(), QVector4D::setY(), QVector4D::toVector3D(), QVector4D::w(), QVector4D::x(), and QVector4D::y().
|
inlineconstexprnoexcept |
Sets the x coordinate of this point to the given finite x coordinate.
Definition at line 674 of file qvectornd.h.
Referenced by operator>>().
|
inlineconstexprnoexcept |
Sets the y coordinate of this point to the given finite y coordinate.
Definition at line 675 of file qvectornd.h.
Referenced by operator>>().
|
inlineconstexprnoexcept |
Sets the z coordinate of this point to the given finite z coordinate.
Definition at line 676 of file qvectornd.h.
Referenced by operator>>().
|
inlineconstexprnoexcept |
Returns the QPoint form of this 3D vector.
The z coordinate is dropped. The x and y coordinates are rounded to nearest integers.
Definition at line 829 of file qvectornd.h.
|
inlineconstexprnoexcept |
Returns the QPointF form of this 3D vector.
The z coordinate is dropped.
Definition at line 834 of file qvectornd.h.
|
inlineconstexprnoexcept |
Returns the 2D vector form of this 3D vector, dropping the z coordinate.
Definition at line 817 of file qvectornd.h.
|
inlineconstexprnoexcept |
Returns the 4D form of this 3D vector, with the w coordinate set to zero.
Definition at line 823 of file qvectornd.h.
QVector3D QVector3D::unproject | ( | const QMatrix4x4 & | modelView, |
const QMatrix4x4 & | projection, | ||
const QRect & | viewport ) const |
Returns the object/model coordinates of this vector initially in window coordinates using the model view matrix modelView, the projection matrix projection and the viewport dimensions viewport.
When transforming from clip to normalized space, a division by the w component of the vector components takes place. To prevent dividing by 0 if w equals to 0, it is set to 1.
Definition at line 815 of file qvectornd.cpp.
References QVector4D::QVector4D(), QVector4D::operator/=(), QVector4D::setW(), QVector4D::setX(), QVector4D::setY(), QVector4D::toVector3D(), QVector4D::w(), QVector4D::x(), and QVector4D::y().
|
inlineconstexprnoexcept |
Returns the x coordinate of this point.
Definition at line 670 of file qvectornd.h.
Referenced by operator<<(), and operator<<().
|
inlineconstexprnoexcept |
Returns the y coordinate of this point.
Definition at line 671 of file qvectornd.h.
Referenced by operator<<(), and operator<<().
|
inlineconstexprnoexcept |
Returns the z coordinate of this point.
Definition at line 672 of file qvectornd.h.
Referenced by operator<<(), and operator<<().
|
friend |
Definition at line 313 of file qvectornd.h.
Returns true
if v1 is not equal to v2; otherwise returns false
.
This operator uses an exact floating-point comparison.
Definition at line 229 of file qvectornd.h.
|
friend |
|
friend |
//!
friend
Returns a copy of the given vector, multiplied by the given finite factor.
Definition at line 250 of file qvectornd.h.
Referenced by distanceToLine().
//!
friend
Returns the QVector3D object formed by multiplying each component of v1 by the corresponding component of v2.
Definition at line 260 of file qvectornd.h.
//!
friend
Returns a copy of the given vector, multiplied by the given finite factor.
Definition at line 255 of file qvectornd.h.
//!
friend
Returns a QVector3D object that is the sum of the given vectors, v1 and v2; each component is added separately.
Definition at line 240 of file qvectornd.h.
Referenced by distanceToLine().
//!
friend
Returns a QVector3D object that is formed by subtracting v2 from v1; each component is subtracted separately.
Definition at line 245 of file qvectornd.h.
Referenced by distanceToLine(), distanceToPlane(), distanceToPlane(), distanceToPoint(), and normal().
//!
friend
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a QVector3D object that is formed by changing the sign of each component of the given vector.
Equivalent to {QVector3D(0,0,0)
- vector}.
Definition at line 265 of file qvectornd.h.
//!
friend
Returns the QVector3D object formed by dividing each component of the given vector by the given divisor.
The divisor must not be either zero or NaN.
Definition at line 270 of file qvectornd.h.
//!
friend
Returns the QVector3D object formed by dividing each component of the given vector by the corresponding component of the given divisor.
The divisor must have no component that is either zero or NaN.
Definition at line 276 of file qvectornd.h.
|
|
friend |
Returns true
if v1 is equal to v2; otherwise returns false
.
This operator uses an exact floating-point comparison.
Definition at line 224 of file qvectornd.h.
|
//!
friend
Returns true
if v1 and v2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.
Definition at line 981 of file qvectornd.cpp.
|
friend |
Definition at line 302 of file qvectornd.h.
|
friend |
Definition at line 303 of file qvectornd.h.