QtBase  v6.3.1
Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QVector4D Class Reference

The QVector4D class represents a vector or vertex in 4D space. More...

#include <qvectornd.h>

Public Member Functions

constexpr QVector4D () noexcept
 
 QVector4D (Qt::Initialization) noexcept
 
constexpr QVector4D (float xpos, float ypos, float zpos, float wpos) noexcept
 
constexpr QVector4D (QPoint point) noexcept
 
constexpr QVector4D (QPointF point) noexcept
 
constexpr QVector4D (QVector2D vector) noexcept
 
constexpr QVector4D (QVector2D vector, float zpos, float wpos) noexcept
 
constexpr QVector4D (QVector3D vector) noexcept
 
constexpr QVector4D (QVector3D vector, float wpos) noexcept
 
constexpr bool isNull () const noexcept
 
constexpr float x () const noexcept
 
constexpr float y () const noexcept
 
constexpr float z () const noexcept
 
constexpr float w () const noexcept
 
constexpr void setX (float x) noexcept
 
constexpr void setY (float y) noexcept
 
constexpr void setZ (float z) noexcept
 
constexpr void setW (float w) noexcept
 
constexpr float & operator[] (int i)
 
constexpr float operator[] (int i) const
 
float length () const noexcept
 
constexpr float lengthSquared () const noexcept
 
QVector4D normalized () const noexcept
 
void normalize () noexcept
 
constexpr QVector4Doperator+= (QVector4D vector) noexcept
 
constexpr QVector4Doperator-= (QVector4D vector) noexcept
 
constexpr QVector4Doperator*= (float factor) noexcept
 
constexpr QVector4Doperator*= (QVector4D vector) noexcept
 
constexpr QVector4Doperator/= (float divisor)
 
constexpr QVector4Doperator/= (QVector4D vector)
 
constexpr QVector2D toVector2D () const noexcept
 
constexpr QVector2D toVector2DAffine () const noexcept
 
constexpr QVector3D toVector3D () const noexcept
 
constexpr QVector3D toVector3DAffine () const noexcept
 
constexpr QPoint toPoint () const noexcept
 
constexpr QPointF toPointF () const noexcept
 
Q_GUI_EXPORT operator QVariant () const
 

Static Public Member Functions

static constexpr float dotProduct (QVector4D v1, QVector4D v2) noexcept
 

Friends

class QVector2D
 
class QVector3D
 
class QMatrix4x4
 
QT_WARNING_PUSH constexpr QT_WARNING_DISABLE_FLOAT_COMPARE friend bool operator== (QVector4D v1, QVector4D v2) noexcept
 
constexpr friend bool operator!= (QVector4D v1, QVector4D v2) noexcept
 
constexpr QT_WARNING_POP friend QVector4D operator+ (QVector4D v1, QVector4D v2) noexcept
 
constexpr friend QVector4D operator- (QVector4D v1, QVector4D v2) noexcept
 
constexpr friend QVector4D operator* (float factor, QVector4D vector) noexcept
 
constexpr friend QVector4D operator* (QVector4D vector, float factor) noexcept
 
constexpr friend QVector4D operator* (QVector4D v1, QVector4D v2) noexcept
 
constexpr friend QVector4D operator- (QVector4D vector) noexcept
 
constexpr friend QVector4D operator/ (QVector4D vector, float divisor)
 
constexpr friend QVector4D operator/ (QVector4D vector, QVector4D divisor)
 
Q_GUI_EXPORT bool qFuzzyCompare (QVector4D v1, QVector4D v2) noexcept
 
QVector4D operator* (const QVector4D &vector, const QMatrix4x4 &matrix)
 
QVector4D operator* (const QMatrix4x4 &matrix, const QVector4D &vector)
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, QVector4D vector)
 
QDataStreamoperator>> (QDataStream &stream, QVector4D &vector)
 

Detailed Description

The QVector4D class represents a vector or vertex in 4D space.

Since
4.6

\inmodule QtGui

Vectors are one of the main building blocks of 4D affine representations of 3D space. They consist of four finite floating-point coordinates, traditionally called x, y, z and w.

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

See also
QQuaternion, QVector2D, QVector3D

Definition at line 368 of file qvectornd.h.

Constructor & Destructor Documentation

◆ QVector4D() [1/9]

constexpr QVector4D::QVector4D ( )
inlineconstexprnoexcept

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

Definition at line 902 of file qvectornd.h.

◆ QVector4D() [2/9]

QVector4D::QVector4D ( Qt::Initialization  )
inlineexplicitnoexcept
Since
5.5

Definition at line 372 of file qvectornd.h.

◆ QVector4D() [3/9]

constexpr QVector4D::QVector4D ( float  xpos,
float  ypos,
float  zpos,
float  wpos 
)
inlineconstexprnoexcept

Constructs a vector with coordinates (xpos, ypos, zpos, wpos). All parameters must be finite.

Definition at line 904 of file qvectornd.h.

◆ QVector4D() [4/9]

constexpr QVector4D::QVector4D ( QPoint  point)
inlineexplicitconstexprnoexcept

Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0.

Definition at line 906 of file qvectornd.h.

◆ QVector4D() [5/9]

constexpr QVector4D::QVector4D ( QPointF  point)
inlineexplicitconstexprnoexcept

Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0.

Definition at line 908 of file qvectornd.h.

◆ QVector4D() [6/9]

constexpr QVector4D::QVector4D ( QVector2D  vector)
explicitconstexprnoexcept

Constructs a 4D vector from the specified 2D vector. The z and w coordinates are set to zero.

See also
toVector2D()

Definition at line 911 of file qvectornd.h.

◆ QVector4D() [7/9]

constexpr QVector4D::QVector4D ( QVector2D  vector,
float  zpos,
float  wpos 
)
constexprnoexcept

Constructs a 4D vector from the specified 2D vector. The z and w coordinates are set to zpos and wpos respectively, each of which must be finite.

See also
toVector2D()

Definition at line 912 of file qvectornd.h.

◆ QVector4D() [8/9]

constexpr QVector4D::QVector4D ( QVector3D  vector)
explicitconstexprnoexcept

Constructs a 4D vector from the specified 3D vector. The w coordinate is set to zero.

See also
toVector3D()

Definition at line 915 of file qvectornd.h.

◆ QVector4D() [9/9]

constexpr QVector4D::QVector4D ( QVector3D  vector,
float  wpos 
)
constexprnoexcept

Constructs a 4D vector from the specified 3D vector. The w coordinate is set to wpos, which must be finite.

See also
toVector3D()

Definition at line 916 of file qvectornd.h.

Member Function Documentation

◆ dotProduct()

constexpr float QVector4D::dotProduct ( QVector4D  v1,
QVector4D  v2 
)
staticconstexprnoexcept

Returns the dot product of v1 and v2.

Definition at line 1034 of file qvectornd.h.

◆ isNull()

constexpr bool QVector4D::isNull ( ) const
inlineconstexprnoexcept

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

Definition at line 919 of file qvectornd.h.

Here is the call graph for this function:

◆ length()

float QVector4D::length ( ) const
inlinenoexcept

Returns the length of the vector from the origin.

See also
lengthSquared(), normalized()

Definition at line 946 of file qvectornd.h.

Here is the call graph for this function:

◆ lengthSquared()

constexpr float QVector4D::lengthSquared ( ) const
inlineconstexprnoexcept

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(), dotProduct()

Definition at line 951 of file qvectornd.h.

◆ normalize()

void QVector4D::normalize ( )
inlinenoexcept

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(), normalized()

Definition at line 963 of file qvectornd.h.

Here is the call graph for this function:

◆ normalized()

QVector4D QVector4D::normalized ( ) const
inlinenoexcept

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(), normalize()

Definition at line 956 of file qvectornd.h.

Here is the call graph for this function:

◆ operator QVariant()

QVector4D::operator QVariant ( ) const

Returns the 4D vector as a QVariant.

Definition at line 1612 of file qvectornd.cpp.

Here is the call graph for this function:

◆ operator*=() [1/2]

constexpr QVector4D & QVector4D::operator*= ( float  factor)
inlineconstexprnoexcept

Multiplies this vector's coordinates by the given finite factor, and returns a reference to this vector.

See also
operator/=(), operator*()

Definition at line 993 of file qvectornd.h.

◆ operator*=() [2/2]

constexpr QVector4D & QVector4D::operator*= ( QVector4D  vector)
inlineconstexprnoexcept

Multiplies each component of this vector by the corresponding component of vector and returns a reference to this vector.

See also
operator/=(), operator*()

Definition at line 1002 of file qvectornd.h.

◆ operator+=()

constexpr QVector4D & QVector4D::operator+= ( QVector4D  vector)
inlineconstexprnoexcept

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

See also
operator-=()

Definition at line 975 of file qvectornd.h.

◆ operator-=()

constexpr QVector4D & QVector4D::operator-= ( QVector4D  vector)
inlineconstexprnoexcept

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

See also
operator+=()

Definition at line 984 of file qvectornd.h.

◆ operator/=() [1/2]

constexpr QVector4D & QVector4D::operator/= ( float  divisor)
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.

See also
operator*=()

Definition at line 1011 of file qvectornd.h.

◆ operator/=() [2/2]

constexpr QVector4D & QVector4D::operator/= ( QVector4D  vector)
inlineconstexpr
Since
5.5

Divides each component of this vector by the corresponding component of vector and returns a reference to this vector.

The vector must have no component that is either zero or NaN.

See also
operator*=(), operator/()

Definition at line 1021 of file qvectornd.h.

◆ operator[]() [1/2]

constexpr float & QVector4D::operator[] ( int  i)
inlineconstexpr
Since
5.2

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 < 4).

Definition at line 934 of file qvectornd.h.

◆ operator[]() [2/2]

constexpr float QVector4D::operator[] ( int  i) const
inlineconstexpr
Since
5.2

Returns the component of the vector at index position i.

i must be a valid index position in the vector (i.e., 0 <= i < 4).

Definition at line 940 of file qvectornd.h.

◆ setW()

constexpr void QVector4D::setW ( float  w)
inlineconstexprnoexcept

Sets the w coordinate of this point to the given finite w coordinate.

See also
w(), setX(), setY(), setZ()

Definition at line 932 of file qvectornd.h.

Here is the caller graph for this function:

◆ setX()

constexpr void QVector4D::setX ( float  x)
inlineconstexprnoexcept

Sets the x coordinate of this point to the given finite x coordinate.

See also
x(), setY(), setZ(), setW()

Definition at line 929 of file qvectornd.h.

Here is the caller graph for this function:

◆ setY()

constexpr void QVector4D::setY ( float  y)
inlineconstexprnoexcept

Sets the y coordinate of this point to the given finite y coordinate.

See also
y(), setX(), setZ(), setW()

Definition at line 930 of file qvectornd.h.

Here is the caller graph for this function:

◆ setZ()

constexpr void QVector4D::setZ ( float  z)
inlineconstexprnoexcept

Sets the z coordinate of this point to the given finite z coordinate.

See also
z(), setX(), setY(), setW()

Definition at line 931 of file qvectornd.h.

◆ toPoint()

constexpr QPoint QVector4D::toPoint ( ) const
inlineconstexprnoexcept

Returns the QPoint form of this 4D vector. The z and w coordinates are dropped. The x and y coordinates are rounded to nearest integers.

See also
toPointF(), toVector2D()

Definition at line 1071 of file qvectornd.h.

Here is the call graph for this function:

◆ toPointF()

constexpr QPointF QVector4D::toPointF ( ) const
inlineconstexprnoexcept

Returns the QPointF form of this 4D vector. The z and w coordinates are dropped.

See also
toPoint(), toVector2D()

Definition at line 1076 of file qvectornd.h.

◆ toVector2D()

constexpr QVector2D QVector4D::toVector2D ( ) const
inlineconstexprnoexcept

Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.

See also
toVector2DAffine(), toVector3D(), toPoint()

Definition at line 1041 of file qvectornd.h.

◆ toVector2DAffine()

constexpr QVector2D QVector4D::toVector2DAffine ( ) const
inlineconstexprnoexcept

Returns the 2D vector form of this 4D vector, dividing the x and y coordinates by the w coordinate and dropping the z coordinate. Returns a null vector if w is zero.

See also
toVector2D(), toVector3DAffine(), toPoint()

Definition at line 1046 of file qvectornd.h.

Here is the call graph for this function:

◆ toVector3D()

constexpr QVector3D QVector4D::toVector3D ( ) const
inlineconstexprnoexcept

Returns the 3D vector form of this 4D vector, dropping the w coordinate.

See also
toVector3DAffine(), toVector2D(), toPoint()

Definition at line 1057 of file qvectornd.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toVector3DAffine()

constexpr QVector3D QVector4D::toVector3DAffine ( ) const
constexprnoexcept

Returns the 3D vector form of this 4D vector, dividing the x, y, and z coordinates by the w coordinate. Returns a null vector if w is zero.

See also
toVector3D(), toVector2DAffine(), toPoint()

Definition at line 1062 of file qvectornd.h.

Here is the call graph for this function:

◆ w()

constexpr float QVector4D::w ( ) const
inlineconstexprnoexcept

Returns the w coordinate of this point.

See also
setW(), x(), y(), z()

Definition at line 927 of file qvectornd.h.

Here is the caller graph for this function:

◆ x()

constexpr float QVector4D::x ( ) const
inlineconstexprnoexcept

Returns the x coordinate of this point.

See also
setX(), y(), z(), w()

Definition at line 924 of file qvectornd.h.

Here is the caller graph for this function:

◆ y()

constexpr float QVector4D::y ( ) const
inlineconstexprnoexcept

Returns the y coordinate of this point.

See also
setY(), x(), z(), w()

Definition at line 925 of file qvectornd.h.

Here is the caller graph for this function:

◆ z()

constexpr float QVector4D::z ( ) const
inlineconstexprnoexcept

Returns the z coordinate of this point.

See also
setZ(), x(), y(), w()

Definition at line 926 of file qvectornd.h.

Friends And Related Function Documentation

◆ operator!=

bool QVector4D::operator!= ( QVector4D  v1,
QVector4D  v2 
)
friend

Returns true if v1 is not equal to v2; otherwise returns false. This operator uses an exact floating-point comparison.

Definition at line 422 of file qvectornd.h.

◆ operator* [1/5]

QVector4D operator* ( const QMatrix4x4 matrix,
const QVector4D vector 
)
friend

Definition at line 789 of file qmatrix4x4.h.

◆ operator* [2/5]

QVector4D operator* ( const QVector4D vector,
const QMatrix4x4 matrix 
)
friend

Definition at line 767 of file qmatrix4x4.h.

◆ operator* [3/5]

const QVector4D QVector4D::operator* ( float  factor,
QVector4D  vector 
)
friend

//! friend

Returns a copy of the given vector, multiplied by the given factor.

See also
QVector4D::operator*=()

Definition at line 437 of file qvectornd.h.

◆ operator* [4/5]

const QVector4D QVector4D::operator* ( QVector4D  v1,
QVector4D  v2 
)
friend

//! friend

Returns the QVector4D object formed by multiplying each component of v1 by the corresponding component of v2.

Note
This is not a cross product of v1 and v2 in any sense. (Its components add up to the dot product of v1 and v2.)
See also
QVector4D::operator*=()

Definition at line 447 of file qvectornd.h.

◆ operator* [5/5]

const QVector4D QVector4D::operator* ( QVector4D  vector,
float  factor 
)
friend

//! friend

Returns a copy of the given vector, multiplied by the given factor.

See also
QVector4D::operator*=()

Definition at line 442 of file qvectornd.h.

◆ operator+

const QVector4D QVector4D::operator+ ( QVector4D  v1,
QVector4D  v2 
)
friend

//! friend

Returns a QVector4D object that is the sum of the given vectors, v1 and v2; each component is added separately.

See also
QVector4D::operator+=()

Definition at line 427 of file qvectornd.h.

◆ operator- [1/2]

const QVector4D QVector4D::operator- ( QVector4D  v1,
QVector4D  v2 
)
friend

//! friend

Returns a QVector4D object that is formed by subtracting v2 from v1; each component is subtracted separately.

See also
QVector4D::operator-=()

Definition at line 432 of file qvectornd.h.

◆ operator- [2/2]

const QVector4D QVector4D::operator- ( QVector4D  vector)
friend

//! 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 QVector4D object that is formed by changing the sign of all three components of the given vector.

Equivalent to {QVector4D(0,0,0,0) - vector}.

Definition at line 452 of file qvectornd.h.

◆ operator/ [1/2]

const QVector4D QVector4D::operator/ ( QVector4D  vector,
float  divisor 
)
friend

//! friend

Returns the QVector4D object formed by dividing each component of the given vector by the given divisor.

The divisor must not be either zero or NaN.

See also
QVector4D::operator/=()

Definition at line 457 of file qvectornd.h.

◆ operator/ [2/2]

const QVector4D QVector4D::operator/ ( QVector4D  vector,
QVector4D  divisor 
)
friend

//! friend

Since
5.5

Returns the QVector4D 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.

See also
QVector4D::operator/=()

Definition at line 463 of file qvectornd.h.

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
QVector4D  vector 
)
related

Writes the given vector to the given stream and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1642 of file qvectornd.cpp.

◆ operator==

bool QVector4D::operator== ( QVector4D  v1,
QVector4D  v2 
)
friend

Returns true if v1 is equal to v2; otherwise returns false. This operator uses an exact floating-point comparison.

Definition at line 417 of file qvectornd.h.

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QVector4D vector 
)
related

Reads a 4D vector from the given stream into the given vector and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1659 of file qvectornd.cpp.

Here is the call graph for this function:

◆ qFuzzyCompare

bool QVector4D::qFuzzyCompare ( QVector4D  v1,
QVector4D  v2 
)
friend

//! friend

Returns true if v1 and v2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise.

Definition at line 1540 of file qvectornd.cpp.

◆ QMatrix4x4

friend class QMatrix4x4
friend

Definition at line 494 of file qvectornd.h.

◆ QVector2D

friend class QVector2D
friend

Definition at line 492 of file qvectornd.h.

◆ QVector3D

friend class QVector3D
friend

Definition at line 493 of file qvectornd.h.


The documentation for this class was generated from the following files: