PySide6.QtGui.QVector4D¶
- class QVector4D¶
The
QVector4D
class represents a vector or vertex in 4D space. More…Added in version 4.6.
Synopsis¶
Methods¶
def
__init__()
def
__reduce__()
def
__repr__()
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
setW()
def
setX()
def
setY()
def
setZ()
def
toPoint()
def
toPointF()
def
toTuple()
def
toVector2D()
def
toVector3D()
def
w()
def
x()
def
y()
def
z()
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 4D affine representations of 3D space. They consist of four finite floating-point coordinates, traditionally called x, y, z and w.
The
QVector4D
class can also be used to represent vertices in 4D 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, 0, 0).
- __init__(point)
- Parameters:
point –
QPoint
Constructs a vector with x and y coordinates from a 2D
point
, and z and w coordinates of 0.- __init__(point)
- Parameters:
point –
QPointF
Constructs a vector with x and y coordinates from a 2D
point
, and z and w coordinates of 0.- __init__(vector)
- Parameters:
vector –
QVector2D
Constructs a 4D vector from the specified 2D
vector
. The z and w coordinates are set to zero.See also
- __init__(vector)
- Parameters:
vector –
QVector3D
Constructs a 4D vector from the specified 3D
vector
. The w coordinate is set to zero.See also
- __init__(vector, wpos)
- Parameters:
vector –
QVector3D
wpos – float
Constructs a 4D vector from the specified 3D
vector
. The w coordinate is set towpos
, which must be finite.See also
- __init__(vector, zpos, wpos)
- Parameters:
vector –
QVector2D
zpos – float
wpos – float
Constructs a 4D vector from the specified 2D
vector
. The z and w coordinates are set tozpos
andwpos
respectively, each of which must be finite.See also
- __init__(xpos, ypos, zpos, wpos)
- Parameters:
xpos – float
ypos – float
zpos – float
wpos – float
Constructs a vector with coordinates (
xpos
,ypos
,zpos
,wpos
). All parameters must be finite.- __reduce__()¶
- Return type:
str
- __repr__()¶
- Return type:
str
Returns the dot product of
v1
andv2
.- isNull()¶
- Return type:
bool
Returns
true
if the x, y, z, and w coordinates are set to 0.0, otherwise returnsfalse
.- 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
true
ifv1
is not equal tov2
; otherwise returnsfalse
. This operator uses an exact floating-point comparison.Returns the
QVector4D
object formed by multiplying each component ofv1
by the corresponding component ofv2
.Note
This is not a cross product of
v1
andv2
in any sense. (Its components add up to the dot product ofv1
andv2
.)See also
operator*=()
- __mul__(matrix)
- Parameters:
matrix –
QMatrix4x4
- Return type:
- __mul__(matrix)
- Parameters:
matrix –
QMatrix4x4
- Return type:
- __mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given
vector
, multiplied by the givenfactor
.See also
operator*=()
- __mul__(factor)
- Parameters:
factor – float
- Return type:
Returns a copy of the given
vector
, multiplied by the givenfactor
.See also
operator*=()
Multiplies each component of this vector by the corresponding component of
vector
and returns a reference to this vector.See also
operator/=()
operator*()
- __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*()
Returns a
QVector4D
object that is the sum of the given vectors,v1
andv2
; each component is added separately.See also
operator+=()
Adds the given
vector
to this vector and returns a reference to this vector.See also
operator-=()
This is an overloaded function.
Returns a
QVector4D
object that is formed by changing the sign of all three components of the givenvector
.Equivalent to
QVector4D(0,0,0,0) - vector
.Returns a
QVector4D
object that is formed by subtractingv2
fromv1
; each component is subtracted separately.See also
operator-=()
Subtracts the given
vector
from this vector and returns a reference to this vector.See also
operator+=()
Returns the
QVector4D
object formed by dividing each component of the givenvector
by the corresponding component of the givendivisor
.The
divisor
must have no component that is either zero or NaN.See also
operator/=()
- __div__(divisor)
- Parameters:
divisor – float
- Return type:
Returns the
QVector4D
object formed by dividing each component of the givenvector
by the givendivisor
.The
divisor
must not be either zero or NaN.See also
operator/=()
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/()
- operator/=(divisor)
- Parameters:
divisor – float
- Return type:
Divides this vector’s coordinates by the given
divisor
, and returns a reference to this vector. Thedivisor
must not be either zero or NaN.See also
operator*=()
Returns
true
ifv1
is equal tov2
; otherwise returnsfalse
. 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
.i
must be a valid index position in the vector (i.e., 0 <=i
< 4).- setW(w)¶
- Parameters:
w – float
Sets the w coordinate of this point to the given finite
w
coordinate.- setX(x)¶
- Parameters:
x – float
Sets the x coordinate of this point to the given finite
x
coordinate.- setY(y)¶
- Parameters:
y – float
Sets the y coordinate of this point to the given finite
y
coordinate.- setZ(z)¶
- Parameters:
z – float
Sets the z coordinate of this point to the given finite
z
coordinate.Returns the QPoint form of this 4D vector. The z and w coordinates are dropped. The x and y coordinates are rounded to nearest integers.
See also
Returns the QPointF form of this 4D vector. The z and w coordinates are dropped.
See also
- toTuple()¶
- Return type:
object
Returns the 2D vector form of this 4D vector, dropping the z and w coordinates.
See also
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
Returns the 3D vector form of this 4D vector, dropping the w coordinate.
See also
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
- w()¶
- Return type:
float
Returns the w coordinate of this point.
- x()¶
- Return type:
float
Returns the x coordinate of this point.
- y()¶
- Return type:
float
Returns the y coordinate of this point.
- z()¶
- Return type:
float
Returns the z coordinate of this point.