QgsVector class

A class to represent a vector.

Currently no Z axis / 2.5D support is implemented.

Constructors, destructors, conversion operators

QgsVector() defaulted
Default constructor for QgsVector.
QgsVector(double x, double y)
Constructor for QgsVector taking x and y component values.

Public functions

auto angle() const -> double
Returns the angle of the vector in radians.
auto angle(QgsVector v) const -> double
Returns the angle between this vector and another vector in radians.
auto crossProduct(QgsVector v) const -> double
Returns the 2D cross product of this vector and another vector v.
auto length() const -> double
Returns the length of the vector.
auto lengthSquared() const -> double
Returns the length of the vector.
auto normalized() const -> QgsVector
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1.0).
auto operator!=(QgsVector other) const -> bool
Inequality operator.
auto operator*(double scalar) const -> QgsVector
Returns a vector where the components have been multiplied by a scalar value.
auto operator*(QgsVector v) const -> double
Returns the dot product of two vectors, which is the sum of the x component of this vector multiplied by the x component of another vector plus the y component of this vector multiplied by the y component of another vector.
auto operator+(QgsVector other) const -> QgsVector
Adds another vector to this vector.
auto operator+=(QgsVector other) -> QgsVector&
Adds another vector to this vector in place.
auto operator-() const -> QgsVector
Swaps the sign of the x and y components of the vector.
auto operator-(QgsVector other) const -> QgsVector
Subtracts another vector to this vector.
auto operator-=(QgsVector other) -> QgsVector&
Subtracts another vector to this vector in place.
auto operator/(double scalar) const -> QgsVector
Returns a vector where the components have been divided by a scalar value.
auto operator==(QgsVector other) const -> bool
Equality operator.
auto perpVector() const -> QgsVector
Returns the perpendicular vector to this vector (rotated 90 degrees counter-clockwise)
auto rotateBy(double rot) const -> QgsVector
Rotates the vector by a specified angle.
auto toString(int precision = 17) const -> QString
Returns a string representation of the vector.
auto x() const -> double
Returns the vector's x-component.
auto y() const -> double
Returns the vector's y-component.

Function documentation

QgsVector::QgsVector() defaulted

Default constructor for QgsVector.

Creates a vector with length of 0.0.

QgsVector::QgsVector(double x, double y)

Constructor for QgsVector taking x and y component values.

Parameters
x x-component
y y-component

double QgsVector::crossProduct(QgsVector v) const

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

double QgsVector::length() const

Returns the length of the vector.

double QgsVector::lengthSquared() const

Returns the length of the vector.

QgsVector QgsVector::normalized() const

Returns the vector's normalized (or "unit") vector (ie same angle but length of 1.0).

Will throw a QgsException if called on a vector with length of 0.

QgsVector QgsVector::operator*(double scalar) const

Returns a vector where the components have been multiplied by a scalar value.

Parameters
scalar factor to multiply by

QgsVector QgsVector::operator+(QgsVector other) const

Adds another vector to this vector.

QgsVector& QgsVector::operator+=(QgsVector other)

Adds another vector to this vector in place.

QgsVector QgsVector::operator-(QgsVector other) const

Subtracts another vector to this vector.

QgsVector& QgsVector::operator-=(QgsVector other)

Subtracts another vector to this vector in place.

QgsVector QgsVector::operator/(double scalar) const

Returns a vector where the components have been divided by a scalar value.

Parameters
scalar factor to divide by

QgsVector QgsVector::rotateBy(double rot) const

Rotates the vector by a specified angle.

Parameters
rot angle in radians

QString QgsVector::toString(int precision = 17) const

Returns a string representation of the vector.

Members will be truncated to the specified precision.

double QgsVector::x() const

Returns the vector's x-component.

double QgsVector::y() const

Returns the vector's y-component.