Class: QgsVector¶
Represent a 2-dimensional vector.
No Z axis / 2.5D support is implemented. See QgsVector3D for
a 3D equivalent.
- class qgis.core.QgsVector[source]¶
Bases:
object- __init__()
Default constructor for QgsVector. Creates a vector with length of 0.0.
- __init__(x: float, y: float)
Constructor for QgsVector taking x and y component values.
- Parameters:
x (float) – x-component
y (float) – y-component
- angle(self) float[source]¶
Returns the angle of the vector in radians.
angle(self, v:
QgsVector) -> float Returns the angle between this vector and another vector in radians.- Return type:
float
- crossProduct(self, v: QgsVector) float[source]¶
Returns the 2D cross product of this vector and another vector
v. (This is sometimes referred to as a “perpendicular dot product”, and equals x1 * y1 - y1 * x2).Added in version 3.2.
- Parameters:
v (QgsVector)
- Return type:
float
- lengthSquared(self) float[source]¶
Returns the length of the vector.
See also
Added in version 3.2.
- Return type:
float
- normalized(self) QgsVector[source]¶
Returns the vector’s normalized (or “unit”) vector (ie same angle but length of 1.0).
- Raises:
QgsException – if called on a vector with length of 0.
- Return type:
- perpVector(self) QgsVector[source]¶
Returns the perpendicular vector to this vector (rotated 90 degrees counter-clockwise)
- Return type:
- rotateBy(self, rot: float) QgsVector[source]¶
Rotates the vector by a specified angle.
- Parameters:
rot (float) – angle in radians
- Return type: