QVector2D#
The QVector2D
class represents a vector or vertex in 2D space. More…
New in version 4.6.
Synopsis#
Functions#
def
__reduce__
()def
__repr__
()def
distanceToLine
(point, direction)def
distanceToPoint
(point)def
isNull
()def
length
()def
lengthSquared
()def
normalize
()def
normalized
()def
__ne__
(v2)def
__mul__
(v2)def
__mul__
(factor)def
__mul__
(factor)def
__imul__
(vector)def
__imul__
(factor)def
__add__
(v2)def
__iadd__
(vector)def
__sub__
()def
__sub__
(v2)def
__isub__
(vector)def
__div__
(divisor)def
__div__
(divisor)def
__idiv__
(vector)def
__idiv__
(divisor)def
__eq__
(v2)def
operator[]
(i)def
setX
(x)def
setY
(y)def
toPoint
()def
toPointF
()def
toTuple
()def
toVector3D
()def
toVector4D
()def
x
()def
y
()
Static functions#
def
dotProduct
(v1, v2)
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
Vectors are one of the main building blocks of 2D representation and drawing. They consist of two finite floating-point coordinates, traditionally called x and y.
The QVector2D
class can also be used to represent vertices in 2D space. We therefore do not need to provide a separate vertex class.
See also
- class PySide6.QtGui.QVector2D#
PySide6.QtGui.QVector2D(point)
PySide6.QtGui.QVector2D(point)
PySide6.QtGui.QVector2D(vector)
PySide6.QtGui.QVector2D(vector)
PySide6.QtGui.QVector2D(xpos, ypos)
- Parameters:
ypos – float
xpos – float
vector –
PySide6.QtGui.QVector3D
point –
PySide6.QtCore.QPoint
Constructs a null vector, i.e. with coordinates (0, 0).
Constructs a vector with x and y coordinates from a 2D point
.
Constructs a vector with x and y coordinates from a 2D point
.
Constructs a vector with x and y coordinates from a 3D vector
. The z coordinate of vector
is dropped.
See also
Constructs a vector with x and y coordinates from a 3D vector
. The z and w coordinates of vector
are dropped.
See also
Constructs a vector with coordinates (xpos
, ypos
). Both coordinates must be finite.
- PySide6.QtGui.QVector2D.__reduce__()#
- Return type:
object
- PySide6.QtGui.QVector2D.__repr__()#
- Return type:
object
- PySide6.QtGui.QVector2D.distanceToLine(point, direction)#
- Parameters:
point –
PySide6.QtGui.QVector2D
direction –
PySide6.QtGui.QVector2D
- Return type:
float
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
- PySide6.QtGui.QVector2D.distanceToPoint(point)#
- Parameters:
point –
PySide6.QtGui.QVector2D
- Return type:
float
Returns the distance from this vertex to a point defined by the vertex point
.
See also
- static PySide6.QtGui.QVector2D.dotProduct(v1, v2)#
- Parameters:
- Return type:
float
Returns the dot product of v1
and v2
.
- PySide6.QtGui.QVector2D.isNull()#
- Return type:
bool
Returns true
if the x and y coordinates are set to 0.0, otherwise returns false
.
- PySide6.QtGui.QVector2D.length()#
- Return type:
float
Returns the length of the vector from the origin.
See also
- PySide6.QtGui.QVector2D.lengthSquared()#
- Return type:
float
Returns the squared length of the vector from the origin. This is equivalent to the dot product of the vector with itself.
See also
- PySide6.QtGui.QVector2D.normalize()#
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.
See also
- PySide6.QtGui.QVector2D.normalized()#
- Return type:
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
- PySide6.QtGui.QVector2D.__ne__(v2)#
- Parameters:
- Return type:
bool
Returns true
if v1
is not equal to v2
; otherwise returns false
. This operator uses an exact floating-point comparison.
- PySide6.QtGui.QVector2D.__mul__(v2)#
- Parameters:
- Return type:
Returns the QVector2D
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
operator*=()
- PySide6.QtGui.QVector2D.__mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given vector
, multiplied by the given finite factor
.
See also
operator*=()
- PySide6.QtGui.QVector2D.__mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given vector
, multiplied by the given finite factor
.
See also
operator*=()
- PySide6.QtGui.QVector2D.__imul__(vector)#
- Parameters:
vector –
PySide6.QtGui.QVector2D
- Return type:
Multiplies each component of this vector by the corresponding component of vector
and returns a reference to this vector.
Note
This is not a cross product of this vector with vector
. (Its components add up to the dot product of this vector and vector
.)
See also
operator/=()
operator*()
- PySide6.QtGui.QVector2D.__imul__(factor)
- Parameters:
factor – float
- Return type:
Multiplies this vector’s coordinates by the given finite factor
and returns a reference to this vector.
See also
operator/=()
operator*()
- PySide6.QtGui.QVector2D.__add__(v2)#
- Parameters:
- Return type:
Returns a QVector2D
object that is the sum of the given vectors, v1
and v2
; each component is added separately.
See also
operator+=()
- PySide6.QtGui.QVector2D.__iadd__(vector)#
- Parameters:
vector –
PySide6.QtGui.QVector2D
- Return type:
Adds the given vector
to this vector and returns a reference to this vector.
See also
operator-=()
- PySide6.QtGui.QVector2D.__sub__()#
- Return type:
This is an overloaded function.
Returns a QVector2D
object that is formed by changing the sign of each component of the given vector
.
Equivalent to QVector2D(0,0) - vector
.
- PySide6.QtGui.QVector2D.__sub__(v2)
- Parameters:
- Return type:
Returns a QVector2D
object that is formed by subtracting v2
from v1
; each component is subtracted separately.
See also
operator-=()
- PySide6.QtGui.QVector2D.__isub__(vector)#
- Parameters:
vector –
PySide6.QtGui.QVector2D
- Return type:
Subtracts the given vector
from this vector and returns a reference to this vector.
See also
operator+=()
- PySide6.QtGui.QVector2D.__div__(divisor)#
- Parameters:
divisor –
PySide6.QtGui.QVector2D
- Return type:
Returns the QVector2D
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
operator/=()
- PySide6.QtGui.QVector2D.__div__(divisor)
- Parameters:
divisor – float
- Return type:
Returns the QVector2D
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
operator/=()
- PySide6.QtGui.QVector2D.__idiv__(vector)#
- Parameters:
vector –
PySide6.QtGui.QVector2D
- Return type:
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/()
- PySide6.QtGui.QVector2D.__idiv__(divisor)
- Parameters:
divisor – float
- Return type:
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*=()
- PySide6.QtGui.QVector2D.__eq__(v2)#
- Parameters:
- Return type:
bool
Returns true
if v1
is equal to v2
; otherwise returns false
. This operator uses an exact floating-point comparison.
- PySide6.QtGui.QVector2D.operator[](i)
- Parameters:
i – int
- Return type:
float
Returns the component of the vector at index position i
.
i
must be a valid index position in the vector (i.e., 0 <= i
< 2).
- PySide6.QtGui.QVector2D.setX(x)#
- Parameters:
x – float
Sets the x coordinate of this point to the given finite x
coordinate.
- PySide6.QtGui.QVector2D.setY(y)#
- Parameters:
y – float
Sets the y coordinate of this point to the given finite y
coordinate.
- PySide6.QtGui.QVector2D.toPoint()#
- Return type:
Returns the QPoint
form of this 2D vector. Each coordinate is rounded to the nearest integer.
See also
- PySide6.QtGui.QVector2D.toPointF()#
- Return type:
Returns the QPointF
form of this 2D vector.
See also
- PySide6.QtGui.QVector2D.toTuple()#
- Return type:
object
- PySide6.QtGui.QVector2D.toVector3D()#
- Return type:
Returns the 3D form of this 2D vector, with the z coordinate set to zero.
See also
- PySide6.QtGui.QVector2D.toVector4D()#
- Return type:
Returns the 4D form of this 2D vector, with the z and w coordinates set to zero.
See also
- PySide6.QtGui.QVector2D.x()#
- Return type:
float
Returns the x coordinate of this point.
- PySide6.QtGui.QVector2D.y()#
- Return type:
float
Returns the y coordinate of this point.