|  | Home · All Classes · Modules

# QVector3D Class Reference
[QtGui module]

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

### Methods

- __init__ (self)
- __init__ (self, float, float, float)
- __init__ (self, QPoint)
- __init__ (self, QPointF)
- __init__ (self, QVector2D)
- __init__ (self, QVector2D, float)
- __init__ (self, QVector4D)
- __init__ (self, QVector3D)
- float distanceToLine (self, QVector3D, QVector3D)
- float distanceToPlane (self, QVector3D, QVector3D)
- float distanceToPlane (self, QVector3D, QVector3D, QVector3D)
- bool isNull (self)
- float length (self)
- float lengthSquared (self)
- normalize (self)
- QVector3D normalized (self)
- setX (self, float)
- setY (self, float)
- setZ (self, float)
- QPoint toPoint (self)
- QPointF toPointF (self)
- QVector2D toVector2D (self)
- QVector4D toVector4D (self)
- float x (self)
- float y (self)
- float z (self)

### Static Methods

- QVector3D crossProduct (QVector3D, QVector3D)
- float dotProduct (QVector3D, QVector3D)
- QVector3D normal (QVector3D, QVector3D)
- QVector3D normal (QVector3D, QVector3D, QVector3D)

### Special Methods

- QVector3D __add__ (self, QVector3D)
- QVector3D __div__ (self, float)
- bool __eq__ (self, QVector3D)
- QVector3D __iadd__ (self, QVector3D)
- QVector3D __idiv__ (self, float)
- QVector3D __imul__ (self, float)
- QVector3D __imul__ (self, QVector3D)
- QVector3D __isub__ (self, QVector3D)
- QVector3D __mul__ (self, QMatrix4x4)
- QVector3D __mul__ (self, QVector3D)
- QVector3D __mul__ (self, float)
- QVector3D __mul__ (self, QVector3D)
- bool __ne__ (self, QVector3D)
- QVector3D __neg__ (self, QVector3D)
- str __repr__ (self)
- QVector3D __sub__ (self, QVector3D)

## 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.

See also QVector2D, QVector4D, and QQuaternion.

## Method Documentation

### QVector3D.__init__ (self)

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

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

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

### QVector3D.__init__ (self, QPoint)

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

### QVector3D.__init__ (self, QPointF)

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

### QVector3D.__init__ (self, QVector2D)

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

See also toVector2D().

### QVector3D.__init__ (self, QVector2D, float)

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

See also toVector2D().

### QVector3D.__init__ (self, QVector4D)

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

See also toVector4D().

### QVector3D.__init__ (self, QVector3D)

### QVector3D QVector3D.crossProduct (QVector3D, QVector3D)

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

See also normal().

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

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.

See also distanceToPlane().

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

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.

See also normal() and distanceToLine().

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

This is an overloaded function.

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.

See also normal() and distanceToLine().

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

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.

See also lengthSquared() and normalized().

### 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.

See also length() and dotProduct().

### QVector3D QVector3D.normal (QVector3D, QVector3D)

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.

See also crossProduct() and distanceToPlane().

### QVector3D QVector3D.normal (QVector3D, QVector3D, QVector3D)

This is an overloaded function.

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.

See also crossProduct() and distanceToPlane().

### 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.

See also length() and normalized().

### 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.

See also length() and normalize().

### QVector3D.setX (self, float)

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

See also x(), setY(), and setZ().

### QVector3D.setY (self, float)

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

See also y(), setX(), and setZ().

### QVector3D.setZ (self, float)

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

See also z(), setX(), and setY().

### QPoint QVector3D.toPoint (self)

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

See also toPointF() and toVector2D().

### QPointF QVector3D.toPointF (self)

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

See also toPoint() and toVector2D().

### QVector2D QVector3D.toVector2D (self)

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

See also toVector4D() and toPoint().

### QVector4D QVector3D.toVector4D (self)

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

See also toVector2D() and toPoint().

### float QVector3D.x (self)

Returns the x coordinate of this point.

See also setX(), y(), and z().

### float QVector3D.y (self)

Returns the y coordinate of this point.

See also setY(), x(), and z().

### float QVector3D.z (self)

Returns the z coordinate of this point.

See also setZ(), x(), and y().

### QVector3D QVector3D.__add__ (self, QVector3D)

### QVector3D QVector3D.__div__ (self, float)

### bool QVector3D.__eq__ (self, QVector3D)

### QVector3D QVector3D.__iadd__ (self, QVector3D)

### QVector3D QVector3D.__idiv__ (self, float)

### QVector3D QVector3D.__imul__ (self, float)

### QVector3D QVector3D.__imul__ (self, QVector3D)

### QVector3D QVector3D.__isub__ (self, QVector3D)

### QVector3D QVector3D.__mul__ (self, QMatrix4x4)

### QVector3D QVector3D.__mul__ (self, QVector3D)

### QVector3D QVector3D.__mul__ (self, float)

### QVector3D QVector3D.__mul__ (self, QVector3D)

### bool QVector3D.__ne__ (self, QVector3D)

### QVector3D QVector3D.__neg__ (self, QVector3D)

### str QVector3D.__repr__ (self)

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