Home · All Classes · Modules

# QVector3D Class Reference[QtGui module]

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

### Static Methods

• QVector3D crossProduct (QVector3D v1, QVector3D v2)
• float dotProduct (QVector3D v1, QVector3D v2)
• QVector3D normal (QVector3D v1, QVector3D v2)
• QVector3D normal (QVector3D v1, QVector3D v2, QVector3D v3)

### Special Methods

• QVector3D __add__ (self, QVector3D v2)
• QVector3D __div__ (self, float divisor)
• bool __eq__ (self, QVector3D v2)
• QVector3D __iadd__ (self, QVector3D vector)
• QVector3D __idiv__ (self, float divisor)
• QVector3D __imul__ (self, float factor)
• QVector3D __imul__ (self, QVector3D vector)
• QVector3D __isub__ (self, QVector3D vector)
• QVector3D __mul__ (self, QMatrix4x4 matrix)
• QVector3D __mul__ (self, QVector3D vector)
• QVector3D __mul__ (self, float factor)
• QVector3D __mul__ (self, QVector3D v2)
• bool __ne__ (self, QVector3D v2)
• QVector3D __neg__ (self)
• str __repr__ (self)
• QVector3D __sub__ (self, QVector3D v2)

## Detailed Description

This class can be pickled.

The QVector3D 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.

The QVector3D 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 the QVector3D instance are stored as float. This means that on platforms where the qreal arguments to QVector3D functions are represented by double values, it is possible to lose precision.

## Method Documentation

### QVector3D.__init__ (self)

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

### QVector3D.__init__ (self, float xpos, float ypos, float zpos)

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

### QVector3D.__init__ (self, QPointpoint)

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

### QVector3D.__init__ (self, QPointFpoint)

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

### QVector3D.__init__ (self, QVector2Dvector)

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

### QVector3D.__init__ (self, QVector2Dvector, float zpos)

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

### QVector3D.__init__ (self, QVector4Dvector)

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

### QVector3D QVector3D.crossProduct (QVector3Dv1, QVector3Dv2)

Returns the cross-product of vectors v1 and v2, which corresponds to the normal vector of a plane defined by v1 and v2.

### float QVector3D.distanceToLine (self, QVector3Dpoint, QVector3Ddirection)

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.

### float QVector3D.distanceToPlane (self, QVector3Dplane, QVector3Dnormal)

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.

### float QVector3D.distanceToPlane (self, QVector3Dplane1, QVector3Dplane2, QVector3Dplane3)

Returns the distance from this vertex 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.

### float QVector3D.dotProduct (QVector3Dv1, QVector3Dv2)

Returns the dot product of v1 and v2.

### bool QVector3D.isNull (self)

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

### float QVector3D.length (self)

Returns the length of the vector from the origin.

### float QVector3D.lengthSquared (self)

Returns the squared length of the vector from the origin. This is equivalent to the dot product of the vector with itself.

### QVector3D QVector3D.normal (QVector3Dv1, QVector3Dv2)

Returns the normal vector of a plane defined by vectors v1 and v2, normalized to be a unit vector.

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.

### QVector3D QVector3D.normal (QVector3Dv1, QVector3Dv2, QVector3Dv3)

Returns the normal vector of a plane defined by vectors v2 - v1 and v3 - v1, normalized to be a unit vector.

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.

### QVector3D.normalize (self)

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.

### QVector3D QVector3D.normalized (self)

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.

### QVector3D.setX (self, float aX)

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

### QVector3D.setY (self, float aY)

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

### QVector3D.setZ (self, float aZ)

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

### QPoint QVector3D.toPoint (self)

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

### QPointF QVector3D.toPointF (self)

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

### QVector2D QVector3D.toVector2D (self)

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

### QVector4D QVector3D.toVector4D (self)

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

### float QVector3D.x (self)

Returns the x coordinate of this point.

### float QVector3D.y (self)

Returns the y coordinate of this point.

### float QVector3D.z (self)

Returns the z coordinate of this point.

### QVector3D QVector3D.__sub__ (self, QVector3Dv2)

 PyQt 4.9.4 for Windows Copyright © Riverbank Computing Ltd and Nokia 2012 Qt 4.8.2