QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
Public Member Functions | List of all members
QgsVector Class Reference

A class to represent a vector. More...

#include <qgsvector.h>

Public Member Functions

 QgsVector ()=default
 Default constructor for QgsVector.
 
 QgsVector (double x, double y)
 Constructor for QgsVector taking x and y component values.
 
double angle () const
 Returns the angle of the vector in radians.
 
double angle (QgsVector v) const
 Returns the angle between this vector and another vector in radians.
 
double crossProduct (QgsVector v) const
 Returns the 2D cross product of this vector and another vector v.
 
double length () const
 Returns the length of the vector.
 
double lengthSquared () const
 Returns the length of the vector.
 
QgsVector normalized () const
 Returns the vector's normalized (or "unit") vector (ie same angle but length of 1.0).
 
bool operator!= (QgsVector other) const
 
QgsVector operator* (double scalar) const
 Returns a vector where the components have been multiplied by a scalar value.
 
double operator* (QgsVector v) const
 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.
 
QgsVector operator+ (QgsVector other) const
 Adds another vector to this vector.
 
QgsVectoroperator+= (QgsVector other)
 Adds another vector to this vector in place.
 
QgsVector operator- () const
 Swaps the sign of the x and y components of the vector.
 
QgsVector operator- (QgsVector other) const
 Subtracts another vector to this vector.
 
QgsVectoroperator-= (QgsVector other)
 Subtracts another vector to this vector in place.
 
QgsVector operator/ (double scalar) const
 Returns a vector where the components have been divided by a scalar value.
 
bool operator== (QgsVector other) const
 
QgsVector perpVector () const
 Returns the perpendicular vector to this vector (rotated 90 degrees counter-clockwise)
 
QgsVector rotateBy (double rot) const
 Rotates the vector by a specified angle.
 
QString toString (int precision=17) const
 Returns a string representation of the vector.
 
double x () const
 Returns the vector's x-component.
 
double y () const
 Returns the vector's y-component.
 

Detailed Description

A class to represent a vector.

Currently no Z axis / 2.5D support is implemented.

Definition at line 29 of file qgsvector.h.

Constructor & Destructor Documentation

◆ QgsVector() [1/2]

QgsVector::QgsVector ( )
default

Default constructor for QgsVector.

Creates a vector with length of 0.0.

◆ QgsVector() [2/2]

QgsVector::QgsVector ( double  x,
double  y 
)
inline

Constructor for QgsVector taking x and y component values.

Parameters
xx-component
yy-component

Definition at line 44 of file qgsvector.h.

Member Function Documentation

◆ angle() [1/2]

double QgsVector::angle ( ) const
inline

Returns the angle of the vector in radians.

Definition at line 168 of file qgsvector.h.

◆ angle() [2/2]

double QgsVector::angle ( QgsVector  v) const
inline

Returns the angle between this vector and another vector in radians.

Definition at line 177 of file qgsvector.h.

◆ crossProduct()

double QgsVector::crossProduct ( QgsVector  v) const
inline

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

Since
QGIS 3.2

Definition at line 188 of file qgsvector.h.

◆ length()

double QgsVector::length ( ) const
inline

Returns the length of the vector.

See also
lengthSquared()

Definition at line 124 of file qgsvector.h.

◆ lengthSquared()

double QgsVector::lengthSquared ( ) const
inline

Returns the length of the vector.

See also
length()
Since
QGIS 3.2

Definition at line 134 of file qgsvector.h.

◆ normalized()

QgsVector QgsVector::normalized ( ) const

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

Exceptions
QgsExceptionif called on a vector with length of 0.

Definition at line 28 of file qgsvector.cpp.

◆ operator!=()

bool QgsVector::operator!= ( QgsVector  other) const
inline

Definition at line 211 of file qgsvector.h.

◆ operator*() [1/2]

QgsVector QgsVector::operator* ( double  scalar) const
inline

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

Parameters
scalarfactor to multiply by

Definition at line 60 of file qgsvector.h.

◆ operator*() [2/2]

double QgsVector::operator* ( QgsVector  v) const
inline

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.

Definition at line 79 of file qgsvector.h.

◆ operator+()

QgsVector QgsVector::operator+ ( QgsVector  other) const
inline

Adds another vector to this vector.

Definition at line 87 of file qgsvector.h.

◆ operator+=()

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

Adds another vector to this vector in place.

Definition at line 95 of file qgsvector.h.

◆ operator-() [1/2]

QgsVector QgsVector::operator- ( ) const
inline

Swaps the sign of the x and y components of the vector.

Definition at line 51 of file qgsvector.h.

◆ operator-() [2/2]

QgsVector QgsVector::operator- ( QgsVector  other) const
inline

Subtracts another vector to this vector.

Definition at line 105 of file qgsvector.h.

◆ operator-=()

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

Subtracts another vector to this vector in place.

Definition at line 113 of file qgsvector.h.

◆ operator/()

QgsVector QgsVector::operator/ ( double  scalar) const
inline

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

Parameters
scalarfactor to divide by

Definition at line 69 of file qgsvector.h.

◆ operator==()

bool QgsVector::operator== ( QgsVector  other) const
inline

Definition at line 206 of file qgsvector.h.

◆ perpVector()

QgsVector QgsVector::perpVector ( ) const
inline

Returns the perpendicular vector to this vector (rotated 90 degrees counter-clockwise)

Definition at line 160 of file qgsvector.h.

◆ rotateBy()

QgsVector QgsVector::rotateBy ( double  rot) const

Rotates the vector by a specified angle.

Parameters
rotangle in radians

Definition at line 21 of file qgsvector.cpp.

◆ toString()

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

Returns a string representation of the vector.

Members will be truncated to the specified precision.

Definition at line 220 of file qgsvector.h.

◆ x()

double QgsVector::x ( ) const
inline

Returns the vector's x-component.

See also
y()

Definition at line 143 of file qgsvector.h.

◆ y()

double QgsVector::y ( ) const
inline

Returns the vector's y-component.

See also
x()

Definition at line 152 of file qgsvector.h.


The documentation for this class was generated from the following files: