PySide6.QtGui.QVector2D¶
- class QVector2D¶
- The - QVector2Dclass represents a vector or vertex in 2D space. More…- Added in version 4.6. - Synopsis¶- Methods¶- def - __init__()
- def - __reduce__()
- def - __repr__()
- def - distanceToLine()
- def - isNull()
- def - length()
- def - lengthSquared()
- def - normalize()
- def - normalized()
- def - __ne__()
- def - __mul__()
- def - __imul__()
- def - __add__()
- def - __iadd__()
- def - __sub__()
- def - __isub__()
- def - __div__()
- def - operator/=()
- def - __eq__()
- def - operator[]()
- def - setX()
- def - setY()
- def - toPoint()
- def - toPointF()
- def - toTuple()
- def - toVector3D()
- def - toVector4D()
- def - x()
- def - y()
 - Static functions¶- def - dotProduct()
 - 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 - QVector2Dclass can also be used to represent vertices in 2D space. We therefore do not need to provide a separate vertex class.- See also - __init__()¶
 - Constructs a null vector, i.e. with coordinates (0, 0). - __init__(point)
- Parameters:
- point – - QPoint
 
 - Constructs a vector with x and y coordinates from a 2D - point.- __init__(point)
- Parameters:
- point – - QPointF
 
 - Constructs a vector with x and y coordinates from a 2D - point.- __init__(vector)
- Parameters:
- vector – - QVector3D
 
 - Constructs a vector with x and y coordinates from a 3D - vector. The z coordinate of- vectoris dropped.- See also - __init__(vector)
- Parameters:
- vector – - QVector4D
 
 - Constructs a vector with x and y coordinates from a 3D - vector. The z and w coordinates of- vectorare dropped.- See also - __init__(xpos, ypos)
- Parameters:
- xpos – float 
- ypos – float 
 
 
 - Constructs a vector with coordinates ( - xpos,- ypos). Both coordinates must be finite.- __reduce__()¶
- Return type:
- str 
 
 - __repr__()¶
- Return type:
- str 
 
 - distanceToLine(point, direction)¶
 - Returns the distance that this vertex is from a line defined by - pointand the unit vector- direction.- If - directionis a null vector, then it does not define a line. In that case, the distance from- pointto this vertex is returned.- See also - Returns the distance from this vertex to a point defined by the vertex - point.- See also - Returns the dot product of - v1and- v2.- isNull()¶
- Return type:
- bool 
 
 - Returns - trueif the x and y coordinates are set to 0.0, otherwise returns- false.- length()¶
- Return type:
- float 
 
 - Returns the length of the vector from the origin. - See also - 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 - 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 - 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 - Returns - trueif- v1is not equal to- v2; otherwise returns- false. This operator uses an exact floating-point comparison.- Returns the - QVector2Dobject formed by multiplying each component of- v1by the corresponding component of- v2.- Note - This is not a cross product of - v1and- v2in any sense. (Its components add up to the dot product of- v1and- v2.)- See also - operator*=()- __mul__(factor)
- Parameters:
- factor – float 
- Return type:
 
 - Returns a copy of the given - vector, multiplied by the given finite- factor.- See also - operator*=()- __mul__(factor)
- Parameters:
- factor – float 
- Return type:
 
 - Returns a copy of the given - vector, multiplied by the given finite- factor.- See also - operator*=()- Multiplies each component of this vector by the corresponding component of - vectorand 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*()- __imul__(factor)
- Parameters:
- factor – float 
- Return type:
 
 - Multiplies this vector’s coordinates by the given finite - factorand returns a reference to this vector.- See also - operator/=()- operator*()- Returns a - QVector2Dobject that is the sum of the given vectors,- v1and- v2; each component is added separately.- See also - operator+=()- Adds the given - vectorto this vector and returns a reference to this vector.- See also - operator-=()- This is an overloaded function. - Returns a - QVector2Dobject that is formed by changing the sign of each component of the given- vector.- Equivalent to - QVector2D(0,0) - vector.- Returns a - QVector2Dobject that is formed by subtracting- v2from- v1; each component is subtracted separately.- See also - operator-=()- Subtracts the given - vectorfrom this vector and returns a reference to this vector.- See also - operator+=()- Returns the - QVector2Dobject formed by dividing each component of the given- vectorby the corresponding component of the given- divisor.- The - divisormust have no component that is either zero or NaN.- See also - operator/=()- __div__(divisor)
- Parameters:
- divisor – float 
- Return type:
 
 - Returns the - QVector2Dobject formed by dividing each component of the given- vectorby the given- divisor.- The - divisormust not be either zero or NaN.- See also - operator/=()- Divides each component of this vector by the corresponding component of - vectorand returns a reference to this vector.- The - vectormust have no component that is either zero or NaN.- See also - operator*=()- operator/()- operator/=(divisor)
- Parameters:
- divisor – float 
- Return type:
 
 - Divides this vector’s coordinates by the given - divisorand returns a reference to this vector. The- divisormust not be either zero or NaN.- See also - operator*=()- Returns - trueif- v1is equal to- v2; otherwise returns- false. This operator uses an exact floating-point comparison.- operator(i)¶
- Parameters:
- i – int 
- Return type:
- float 
 
 - Returns the component of the vector at index position - i.- imust be a valid index position in the vector (i.e., 0 <=- i< 2).- setX(x)¶
- Parameters:
- x – float 
 
 - Sets the x coordinate of this point to the given finite - xcoordinate.- setY(y)¶
- Parameters:
- y – float 
 
 - Sets the y coordinate of this point to the given finite - ycoordinate.- Returns the QPoint form of this 2D vector. Each coordinate is rounded to the nearest integer. - See also - Returns the QPointF form of this 2D vector. - See also - toTuple()¶
- Return type:
- object 
 
 - Returns the 3D form of this 2D vector, with the z coordinate set to zero. - See also - Returns the 4D form of this 2D vector, with the z and w coordinates set to zero. - See also - x()¶
- Return type:
- float 
 
 - Returns the x coordinate of this point. - y()¶
- Return type:
- float 
 
 - Returns the y coordinate of this point.