Qt 4.8
Public Functions | Static Public Functions | Private Functions | Properties | Friends | Related Functions | List of all members
QVector4D Class Reference

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

#include <qvector4d.h>

Public Functions

bool isNull () const
 Returns true if the x, y, z, and w coordinates are set to 0. More...
 
qreal length () const
 Returns the length of the vector from the origin. More...
 
qreal lengthSquared () const
 Returns the squared length of the vector from the origin. More...
 
void normalize ()
 Normalizes the currect vector in place. More...
 
QVector4D normalized () const
 Returns the normalized unit vector form of this vector. More...
 
 operator QVariant () const
 Returns the 4D vector as a QVariant. More...
 
QVector4Doperator*= (qreal factor)
 Multiplies this vector's coordinates by the given factor, and returns a reference to this vector. More...
 
QVector4Doperator*= (const QVector4D &vector)
 Multiplies the components of this vector by the corresponding components in vector. More...
 
QVector4Doperator+= (const QVector4D &vector)
 Adds the given vector to this vector and returns a reference to this vector. More...
 
QVector4Doperator-= (const QVector4D &vector)
 Subtracts the given vector from this vector and returns a reference to this vector. More...
 
QVector4Doperator/= (qreal divisor)
 Divides this vector's coordinates by the given divisor, and returns a reference to this vector. More...
 
 QVector4D ()
 Constructs a null vector, i. More...
 
 QVector4D (qreal xpos, qreal ypos, qreal zpos, qreal wpos)
 Constructs a vector with coordinates (xpos, ypos, zpos, wpos). More...
 
 QVector4D (const QPoint &point)
 Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0. More...
 
 QVector4D (const QPointF &point)
 Constructs a vector with x and y coordinates from a 2D point, and z and w coordinates of 0. More...
 
 QVector4D (const QVector2D &vector)
 Constructs a 4D vector from the specified 2D vector. More...
 
 QVector4D (const QVector2D &vector, qreal zpos, qreal wpos)
 Constructs a 4D vector from the specified 2D vector. More...
 
 QVector4D (const QVector3D &vector)
 Constructs a 4D vector from the specified 3D vector. More...
 
 QVector4D (const QVector3D &vector, qreal wpos)
 Constructs a 4D vector from the specified 3D vector. More...
 
void setW (qreal w)
 Sets the w coordinate of this point to the given w coordinate. More...
 
void setX (qreal x)
 Sets the x coordinate of this point to the given x coordinate. More...
 
void setY (qreal y)
 Sets the y coordinate of this point to the given y coordinate. More...
 
void setZ (qreal z)
 Sets the z coordinate of this point to the given z coordinate. More...
 
QPoint toPoint () const
 Returns the QPoint form of this 4D vector. More...
 
QPointF toPointF () const
 Returns the QPointF form of this 4D vector. More...
 
QVector2D toVector2D () const
 Returns the 2D vector form of this 4D vector, dropping the z and w coordinates. More...
 
QVector2D toVector2DAffine () const
 Returns the 2D vector form of this 4D vector, dividing the x and y coordinates by the w coordinate and dropping the z coordinate. More...
 
QVector3D toVector3D () const
 Returns the 3D vector form of this 4D vector, dropping the w coordinate. More...
 
QVector3D toVector3DAffine () const
 Returns the 3D vector form of this 4D vector, dividing the x, y, and z coordinates by the w coordinate. More...
 
qreal w () const
 Returns the w coordinate of this point. More...
 
qreal x () const
 Returns the x coordinate of this point. More...
 
qreal y () const
 Returns the y coordinate of this point. More...
 
qreal z () const
 Returns the z coordinate of this point. More...
 

Static Public Functions

static qreal dotProduct (const QVector4D &v1, const QVector4D &v2)
 Returns the dot product of v1 and v2. More...
 

Private Functions

 QVector4D (float xpos, float ypos, float zpos, float wpos, int dummy)
 

Properties

float wp
 
float xp
 
float yp
 
float zp
 

Friends

bool operator!= (const QVector4D &v1, const QVector4D &v2)
 Returns true if v1 is not equal to v2; otherwise returns false. More...
 
const QVector4D operator* (qreal factor, const QVector4D &vector)
 
const QVector4D operator* (const QVector4D &vector, qreal factor)
 
const QVector4D operator* (const QVector4D &v1, const QVector4D &v2)
 
QVector4D operator* (const QVector4D &vector, const QMatrix4x4 &matrix)
 
QVector4D operator* (const QMatrix4x4 &matrix, const QVector4D &vector)
 
const QVector4D operator+ (const QVector4D &v1, const QVector4D &v2)
 Returns a QVector4D object that is the sum of the given vectors, v1 and v2; each component is added separately. More...
 
const QVector4D operator- (const QVector4D &v1, const QVector4D &v2)
 Returns a QVector4D object that is formed by subtracting v2 from v1; each component is subtracted separately. More...
 
const QVector4D operator- (const QVector4D &vector)
 Returns a QVector4D object that is formed by changing the sign of all three components of the given vector. More...
 
const QVector4D operator/ (const QVector4D &vector, qreal divisor)
 Returns the QVector4D object formed by dividing all four components of the given vector by the given divisor. More...
 
bool operator== (const QVector4D &v1, const QVector4D &v2)
 Returns true if v1 is equal to v2; otherwise returns false. More...
 
bool qFuzzyCompare (const QVector4D &v1, const QVector4D &v2)
 Returns true if v1 and v2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise. More...
 
class QVector2D
 
class QVector3D
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QVector4D &vector)
 Writes the given vector to the given stream and returns a reference to the stream. More...
 
QDataStreamoperator>> (QDataStream &stream, QVector4D &vector)
 Reads a 4D vector from the given stream into the given vector and returns a reference to the stream. More...
 

Detailed Description

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

Since
4.6

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

Note: By design values in the QVector4D instance are stored as float. This means that on platforms where the qreal arguments to QVector4D functions are represented by double values, it is possible to lose precision.

See also
QQuaternion, QVector2D, QVector3D

Definition at line 60 of file qvector4d.h.

Constructors and Destructors

◆ QVector4D() [1/9]

QVector4D::QVector4D ( )
inline

Constructs a null vector, i.

e. with coordinates (0, 0, 0, 0).

Definition at line 143 of file qvector4d.h.

Referenced by normalized(), operator*(), operator+(), operator-(), and operator/().

143 : xp(0.0f), yp(0.0f), zp(0.0f), wp(0.0f) {}
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ QVector4D() [2/9]

QVector4D::QVector4D ( qreal  xpos,
qreal  ypos,
qreal  zpos,
qreal  wpos 
)
inline

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

Definition at line 145 of file qvector4d.h.

145 : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {}
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ QVector4D() [3/9]

QVector4D::QVector4D ( const QPoint point)
inlineexplicit

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

Definition at line 149 of file qvector4d.h.

149 : xp(point.x()), yp(point.y()), zp(0.0f), wp(0.0f) {}
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
float xp
Definition: qvector4d.h:129

◆ QVector4D() [4/9]

QVector4D::QVector4D ( const QPointF point)
inlineexplicit

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

Definition at line 151 of file qvector4d.h.

151 : xp(point.x()), yp(point.y()), zp(0.0f), wp(0.0f) {}
float yp
Definition: qvector4d.h:129
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
float xp
Definition: qvector4d.h:129

◆ QVector4D() [5/9]

QVector4D::QVector4D ( const QVector2D vector)

Constructs a 4D vector from the specified 2D vector.

The z and w coordinates are set to zero.

See also
toVector2D()

Definition at line 119 of file qvector4d.cpp.

120 {
121  xp = vector.xp;
122  yp = vector.yp;
123  zp = 0.0f;
124  wp = 0.0f;
125 }
float xp
Definition: qvector2d.h:121
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float yp
Definition: qvector2d.h:121
float xp
Definition: qvector4d.h:129

◆ QVector4D() [6/9]

QVector4D::QVector4D ( const QVector2D vector,
qreal  zpos,
qreal  wpos 
)

Constructs a 4D vector from the specified 2D vector.

The z and w coordinates are set to zpos and wpos respectively.

See also
toVector2D()

Definition at line 133 of file qvector4d.cpp.

134 {
135  xp = vector.xp;
136  yp = vector.yp;
137  zp = zpos;
138  wp = wpos;
139 }
float xp
Definition: qvector2d.h:121
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float yp
Definition: qvector2d.h:121
float xp
Definition: qvector4d.h:129

◆ QVector4D() [7/9]

QVector4D::QVector4D ( const QVector3D vector)

Constructs a 4D vector from the specified 3D vector.

The w coordinate is set to zero.

See also
toVector3D()

Definition at line 151 of file qvector4d.cpp.

152 {
153  xp = vector.xp;
154  yp = vector.yp;
155  zp = vector.zp;
156  wp = 0.0f;
157 }
float zp
Definition: qvector3d.h:132
float yp
Definition: qvector4d.h:129
float yp
Definition: qvector3d.h:132
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector3d.h:132
float xp
Definition: qvector4d.h:129

◆ QVector4D() [8/9]

QVector4D::QVector4D ( const QVector3D vector,
qreal  wpos 
)

Constructs a 4D vector from the specified 3D vector.

The w coordinate is set to wpos.

See also
toVector3D()

Definition at line 165 of file qvector4d.cpp.

166 {
167  xp = vector.xp;
168  yp = vector.yp;
169  zp = vector.zp;
170  wp = wpos;
171 }
float zp
Definition: qvector3d.h:132
float yp
Definition: qvector4d.h:129
float yp
Definition: qvector3d.h:132
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector3d.h:132
float xp
Definition: qvector4d.h:129

◆ QVector4D() [9/9]

QVector4D::QVector4D ( float  xpos,
float  ypos,
float  zpos,
float  wpos,
int  dummy 
)
inlineprivate

Definition at line 147 of file qvector4d.h.

147 : xp(xpos), yp(ypos), zp(zpos), wp(wpos) {}
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

Functions

◆ dotProduct()

qreal QVector4D::dotProduct ( const QVector4D v1,
const QVector4D v2 
)
static

Returns the dot product of v1 and v2.

Definition at line 394 of file qvector4d.cpp.

395 {
396  return v1.xp * v2.xp + v1.yp * v2.yp + v1.zp * v2.zp + v1.wp * v2.wp;
397 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ isNull()

bool QVector4D::isNull ( ) const
inline

Returns true if the x, y, z, and w coordinates are set to 0.

0, otherwise returns false.

Definition at line 153 of file qvector4d.h.

154 {
155  return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && qIsNull(wp);
156 }
float yp
Definition: qvector4d.h:129
static bool qIsNull(double d)
Definition: qglobal.h:2061
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ length()

qreal QVector4D::length ( ) const

Returns the length of the vector from the origin.

See also
lengthSquared(), normalized()

Definition at line 278 of file qvector4d.cpp.

279 {
280  return qSqrt(xp * xp + yp * yp + zp * zp + wp * wp);
281 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ lengthSquared()

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

Definition at line 289 of file qvector4d.cpp.

290 {
291  return xp * xp + yp * yp + zp * zp + wp * wp;
292 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ normalize()

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

Definition at line 324 of file qvector4d.cpp.

325 {
326  // Need some extra precision if the length is very small.
327  double len = double(xp) * double(xp) +
328  double(yp) * double(yp) +
329  double(zp) * double(zp) +
330  double(wp) * double(wp);
331  if (qFuzzyIsNull(len - 1.0f) || qFuzzyIsNull(len))
332  return;
333 
334  len = qSqrt(len);
335 
336  xp /= len;
337  yp /= len;
338  zp /= len;
339  wp /= len;
340 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
float xp
Definition: qvector4d.h:129
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ normalized()

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

Definition at line 303 of file qvector4d.cpp.

304 {
305  // Need some extra precision if the length is very small.
306  double len = double(xp) * double(xp) +
307  double(yp) * double(yp) +
308  double(zp) * double(zp) +
309  double(wp) * double(wp);
310  if (qFuzzyIsNull(len - 1.0f))
311  return *this;
312  else if (!qFuzzyIsNull(len))
313  return *this / qSqrt(len);
314  else
315  return QVector4D();
316 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
float zp
Definition: qvector4d.h:129
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
float xp
Definition: qvector4d.h:129
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ operator QVariant()

QVector4D::operator QVariant ( ) const

Returns the 4D vector as a QVariant.

Definition at line 595 of file qvector4d.cpp.

596 {
597  return QVariant(QVariant::Vector4D, this);
598 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator*=() [1/2]

QVector4D & QVector4D::operator*= ( qreal  factor)
inline

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

See also
operator/=()

Definition at line 186 of file qvector4d.h.

187 {
188  xp *= factor;
189  yp *= factor;
190  zp *= factor;
191  wp *= factor;
192  return *this;
193 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator*=() [2/2]

QVector4D & QVector4D::operator*= ( const QVector4D vector)
inline

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

Definition at line 195 of file qvector4d.h.

196 {
197  xp *= vector.xp;
198  yp *= vector.yp;
199  zp *= vector.zp;
200  wp *= vector.wp;
201  return *this;
202 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator+=()

QVector4D & QVector4D::operator+= ( const QVector4D vector)
inline

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

See also
operator-=()

Definition at line 168 of file qvector4d.h.

169 {
170  xp += vector.xp;
171  yp += vector.yp;
172  zp += vector.zp;
173  wp += vector.wp;
174  return *this;
175 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator-=()

QVector4D & QVector4D::operator-= ( const QVector4D vector)
inline

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

See also
operator+=()

Definition at line 177 of file qvector4d.h.

178 {
179  xp -= vector.xp;
180  yp -= vector.yp;
181  zp -= vector.zp;
182  wp -= vector.wp;
183  return *this;
184 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator/=()

QVector4D & QVector4D::operator/= ( qreal  divisor)
inline

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

See also
operator*=()

Definition at line 204 of file qvector4d.h.

205 {
206  xp /= divisor;
207  yp /= divisor;
208  zp /= divisor;
209  wp /= divisor;
210  return *this;
211 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ setW()

void QVector4D::setW ( qreal  w)
inline

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

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

Definition at line 166 of file qvector4d.h.

Referenced by operator>>(), and QDeclarativeVector4DValueType::setW().

166 { wp = aW; }
float wp
Definition: qvector4d.h:129

◆ setX()

void QVector4D::setX ( qreal  x)
inline

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

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

Definition at line 163 of file qvector4d.h.

Referenced by operator>>(), and QDeclarativeVector4DValueType::setX().

163 { xp = aX; }
float xp
Definition: qvector4d.h:129

◆ setY()

void QVector4D::setY ( qreal  y)
inline

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

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

Definition at line 164 of file qvector4d.h.

Referenced by operator>>(), and QDeclarativeVector4DValueType::setY().

164 { yp = aY; }
float yp
Definition: qvector4d.h:129

◆ setZ()

void QVector4D::setZ ( qreal  z)
inline

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

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

Definition at line 165 of file qvector4d.h.

Referenced by operator>>(), and QDeclarativeVector4DValueType::setZ().

165 { zp = aZ; }
float zp
Definition: qvector4d.h:129

◆ toPoint()

QPoint QVector4D::toPoint ( ) const
inline

Returns the QPoint form of this 4D vector.

The z and w coordinates are dropped.

See also
toPointF(), toVector2D()

Definition at line 266 of file qvector4d.h.

267 {
268  return QPoint(qRound(xp), qRound(yp));
269 }
float yp
Definition: qvector4d.h:129
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
float xp
Definition: qvector4d.h:129
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ toPointF()

QPointF QVector4D::toPointF ( ) const
inline

Returns the QPointF form of this 4D vector.

The z and w coordinates are dropped.

See also
toPoint(), toVector2D()

Definition at line 271 of file qvector4d.h.

272 {
273  return QPointF(qreal(xp), qreal(yp));
274 }
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
float yp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ toVector2D()

QVector2D QVector4D::toVector2D ( ) const

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

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

Definition at line 520 of file qvector4d.cpp.

521 {
522  return QVector2D(xp, yp, 1);
523 }
float yp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129
friend class QVector2D
Definition: qvector4d.h:133

◆ toVector2DAffine()

QVector2D QVector4D::toVector2DAffine ( ) const

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 532 of file qvector4d.cpp.

533 {
534  if (qIsNull(wp))
535  return QVector2D();
536  return QVector2D(xp / wp, yp / wp, 1);
537 }
float yp
Definition: qvector4d.h:129
static bool qIsNull(double d)
Definition: qglobal.h:2061
float wp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129
friend class QVector2D
Definition: qvector4d.h:133

◆ toVector3D()

QVector3D QVector4D::toVector3D ( ) const

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

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

Definition at line 548 of file qvector4d.cpp.

549 {
550  return QVector3D(xp, yp, zp, 1);
551 }
float yp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
friend class QVector3D
Definition: qvector4d.h:134
float xp
Definition: qvector4d.h:129

◆ toVector3DAffine()

QVector3D QVector4D::toVector3DAffine ( ) const

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 559 of file qvector4d.cpp.

560 {
561  if (qIsNull(wp))
562  return QVector3D();
563  return QVector3D(xp / wp, yp / wp, zp / wp, 1);
564 }
float yp
Definition: qvector4d.h:129
static bool qIsNull(double d)
Definition: qglobal.h:2061
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
friend class QVector3D
Definition: qvector4d.h:134
float xp
Definition: qvector4d.h:129

◆ w()

qreal QVector4D::w ( ) const
inline

Returns the w coordinate of this point.

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

Definition at line 161 of file qvector4d.h.

Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::setColumn(), QMatrix4x4::setRow(), and QDeclarativeVector4DValueType::setValue().

161 { return qreal(wp); }
double qreal
Definition: qglobal.h:1193
float wp
Definition: qvector4d.h:129

◆ x()

qreal QVector4D::x ( ) const
inline

Returns the x coordinate of this point.

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

Definition at line 158 of file qvector4d.h.

Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::setColumn(), QMatrix4x4::setRow(), and QDeclarativeVector4DValueType::setValue().

158 { return qreal(xp); }
double qreal
Definition: qglobal.h:1193
float xp
Definition: qvector4d.h:129

◆ y()

qreal QVector4D::y ( ) const
inline

Returns the y coordinate of this point.

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

Definition at line 159 of file qvector4d.h.

Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::setColumn(), QMatrix4x4::setRow(), and QDeclarativeVector4DValueType::setValue().

159 { return qreal(yp); }
double qreal
Definition: qglobal.h:1193
float yp
Definition: qvector4d.h:129

◆ z()

qreal QVector4D::z ( ) const
inline

Returns the z coordinate of this point.

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

Definition at line 160 of file qvector4d.h.

Referenced by operator*(), operator<<(), operator>>(), QMatrix4x4::setColumn(), QMatrix4x4::setRow(), and QDeclarativeVector4DValueType::setValue().

160 { return qreal(zp); }
double qreal
Definition: qglobal.h:1193
float zp
Definition: qvector4d.h:129

Friends and Related Functions

◆ operator!=

bool operator!= ( const QVector4D v1,
const 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 218 of file qvector4d.h.

219 {
220  return v1.xp != v2.xp || v1.yp != v2.yp || v1.zp != v2.zp || v1.wp != v2.wp;
221 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator* [1/5]

const QVector4D operator* ( qreal  factor,
const QVector4D vector 
)
friend

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

See also
QVector4D::operator*=()

Definition at line 233 of file qvector4d.h.

234 {
235  return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor, 1);
236 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator* [2/5]

const QVector4D operator* ( const QVector4D vector,
qreal  factor 
)
friend

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

See also
QVector4D::operator*=()

Definition at line 238 of file qvector4d.h.

239 {
240  return QVector4D(vector.xp * factor, vector.yp * factor, vector.zp * factor, vector.wp * factor, 1);
241 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator* [3/5]

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

Returns the vector consisting of the multiplication of the components from v1 and v2.

See also
QVector4D::operator*=()

Definition at line 243 of file qvector4d.h.

244 {
245  return QVector4D(v1.xp * v2.xp, v1.yp * v2.yp, v1.zp * v2.zp, v1.wp * v2.wp, 1);
246 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator* [4/5]

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

Definition at line 677 of file qmatrix4x4.h.

678 {
679  qreal x, y, z, w;
680  x = vector.x() * matrix.m[0][0] +
681  vector.y() * matrix.m[0][1] +
682  vector.z() * matrix.m[0][2] +
683  vector.w() * matrix.m[0][3];
684  y = vector.x() * matrix.m[1][0] +
685  vector.y() * matrix.m[1][1] +
686  vector.z() * matrix.m[1][2] +
687  vector.w() * matrix.m[1][3];
688  z = vector.x() * matrix.m[2][0] +
689  vector.y() * matrix.m[2][1] +
690  vector.z() * matrix.m[2][2] +
691  vector.w() * matrix.m[2][3];
692  w = vector.x() * matrix.m[3][0] +
693  vector.y() * matrix.m[3][1] +
694  vector.z() * matrix.m[3][2] +
695  vector.w() * matrix.m[3][3];
696  return QVector4D(x, y, z, w);
697 }
double qreal
Definition: qglobal.h:1193
qreal w() const
Returns the w coordinate of this point.
Definition: qvector4d.h:161
qreal x() const
Returns the x coordinate of this point.
Definition: qvector4d.h:158
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal z() const
Returns the z coordinate of this point.
Definition: qvector4d.h:160
qreal y() const
Returns the y coordinate of this point.
Definition: qvector4d.h:159

◆ operator* [5/5]

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

Definition at line 699 of file qmatrix4x4.h.

700 {
701  qreal x, y, z, w;
702  x = vector.x() * matrix.m[0][0] +
703  vector.y() * matrix.m[1][0] +
704  vector.z() * matrix.m[2][0] +
705  vector.w() * matrix.m[3][0];
706  y = vector.x() * matrix.m[0][1] +
707  vector.y() * matrix.m[1][1] +
708  vector.z() * matrix.m[2][1] +
709  vector.w() * matrix.m[3][1];
710  z = vector.x() * matrix.m[0][2] +
711  vector.y() * matrix.m[1][2] +
712  vector.z() * matrix.m[2][2] +
713  vector.w() * matrix.m[3][2];
714  w = vector.x() * matrix.m[0][3] +
715  vector.y() * matrix.m[1][3] +
716  vector.z() * matrix.m[2][3] +
717  vector.w() * matrix.m[3][3];
718  return QVector4D(x, y, z, w);
719 }
double qreal
Definition: qglobal.h:1193
qreal w() const
Returns the w coordinate of this point.
Definition: qvector4d.h:161
qreal x() const
Returns the x coordinate of this point.
Definition: qvector4d.h:158
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
qreal m[4][4]
Definition: qmatrix4x4.h:188
qreal z() const
Returns the z coordinate of this point.
Definition: qvector4d.h:160
qreal y() const
Returns the y coordinate of this point.
Definition: qvector4d.h:159

◆ operator+

const QVector4D operator+ ( const QVector4D v1,
const QVector4D v2 
)
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 223 of file qvector4d.h.

224 {
225  return QVector4D(v1.xp + v2.xp, v1.yp + v2.yp, v1.zp + v2.zp, v1.wp + v2.wp, 1);
226 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator- [1/2]

const QVector4D operator- ( const QVector4D v1,
const QVector4D v2 
)
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 228 of file qvector4d.h.

229 {
230  return QVector4D(v1.xp - v2.xp, v1.yp - v2.yp, v1.zp - v2.zp, v1.wp - v2.wp, 1);
231 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator- [2/2]

const QVector4D operator- ( const QVector4D vector)
friend

Returns a QVector4D object that is formed by changing the sign of all three components of the given vector.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 248 of file qvector4d.h.

249 {
250  return QVector4D(-vector.xp, -vector.yp, -vector.zp, -vector.wp, 1);
251 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator/

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

Returns the QVector4D object formed by dividing all four components of the given vector by the given divisor.

See also
QVector4D::operator/=()

Definition at line 253 of file qvector4d.h.

254 {
255  return QVector4D(vector.xp / divisor, vector.yp / divisor, vector.zp / divisor, vector.wp / divisor, 1);
256 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
QVector4D()
Constructs a null vector, i.
Definition: qvector4d.h:143
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const 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 627 of file qvector4d.cpp.

Referenced by toPointF().

628 {
629  stream << double(vector.x()) << double(vector.y())
630  << double(vector.z()) << double(vector.w());
631  return stream;
632 }
qreal w() const
Returns the w coordinate of this point.
Definition: qvector4d.h:161
static FILE * stream
qreal x() const
Returns the x coordinate of this point.
Definition: qvector4d.h:158
qreal z() const
Returns the z coordinate of this point.
Definition: qvector4d.h:160
qreal y() const
Returns the y coordinate of this point.
Definition: qvector4d.h:159

◆ operator==

bool operator== ( const QVector4D v1,
const 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 213 of file qvector4d.h.

214 {
215  return v1.xp == v2.xp && v1.yp == v2.yp && v1.zp == v2.zp && v1.wp == v2.wp;
216 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ 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 647 of file qvector4d.cpp.

Referenced by toPointF().

648 {
649  double x, y, z, w;
650  stream >> x;
651  stream >> y;
652  stream >> z;
653  stream >> w;
654  vector.setX(qreal(x));
655  vector.setY(qreal(y));
656  vector.setZ(qreal(z));
657  vector.setW(qreal(w));
658  return stream;
659 }
double qreal
Definition: qglobal.h:1193
qreal w() const
Returns the w coordinate of this point.
Definition: qvector4d.h:161
static FILE * stream
qreal x() const
Returns the x coordinate of this point.
Definition: qvector4d.h:158
void setZ(qreal z)
Sets the z coordinate of this point to the given z coordinate.
Definition: qvector4d.h:165
void setW(qreal w)
Sets the w coordinate of this point to the given w coordinate.
Definition: qvector4d.h:166
void setX(qreal x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qvector4d.h:163
void setY(qreal y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qvector4d.h:164
qreal z() const
Returns the z coordinate of this point.
Definition: qvector4d.h:160
qreal y() const
Returns the y coordinate of this point.
Definition: qvector4d.h:159

◆ qFuzzyCompare

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

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

Definition at line 258 of file qvector4d.h.

Referenced by qFuzzyCompare().

259 {
260  return qFuzzyCompare(v1.xp, v2.xp) &&
261  qFuzzyCompare(v1.yp, v2.yp) &&
262  qFuzzyCompare(v1.zp, v2.zp) &&
263  qFuzzyCompare(v1.wp, v2.wp);
264 }
float yp
Definition: qvector4d.h:129
float wp
Definition: qvector4d.h:129
friend bool qFuzzyCompare(const QVector4D &v1, const QVector4D &v2)
Returns true if v1 and v2 are equal, allowing for a small fuzziness factor for floating-point compari...
Definition: qvector4d.h:258
float zp
Definition: qvector4d.h:129
float xp
Definition: qvector4d.h:129

◆ QVector2D

friend class QVector2D
friend

Definition at line 133 of file qvector4d.h.

Referenced by toVector2D(), and toVector2DAffine().

◆ QVector3D

friend class QVector3D
friend

Definition at line 134 of file qvector4d.h.

Referenced by toVector3D(), and toVector3DAffine().

Properties

◆ wp

float QVector4D::wp
private

◆ xp

float QVector4D::xp
private

◆ yp

float QVector4D::yp
private

◆ zp

float QVector4D::zp
private

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