QGIS API Documentation  2.99.0-Master (7d4f81d)
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 constructor for QgsVector. More...
 
 QgsVector (double x, double y)
 Constructor for QgsVector taking x and y component values. More...
 
double angle () const
 Returns the angle of the vector in radians. More...
 
double angle (QgsVector v) const
 Returns the angle between this vector and another vector in radians. More...
 
double length () const
 Returns the length of the vector. More...
 
QgsVector normalized () const
 Returns the vector's normalized (or "unit") vector (ie same angle but length of 1.0). More...
 
bool operator!= (QgsVector other) const
 Inequality operator. More...
 
QgsVector operator* (double scalar) const
 Returns a vector where the components have been multiplied by a scalar value. More...
 
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. More...
 
QgsVector operator+ (QgsVector other) const
 Adds another vector to this vector. More...
 
QgsVectoroperator+= (const QgsVector other)
 Adds another vector to this vector in place. More...
 
QgsVector operator- () const
 Swaps the sign of the x and y components of the vector. More...
 
QgsVector operator- (const QgsVector other) const
 Subtracts another vector to this vector. More...
 
QgsVectoroperator-= (const QgsVector other)
 Subtracts another vector to this vector in place. More...
 
QgsVector operator/ (double scalar) const
 Returns a vector where the components have been divided by a scalar value. More...
 
bool operator== (QgsVector other) const
 Equality operator. More...
 
QgsVector perpVector () const
 Returns the perpendicular vector to this vector (rotated 90 degrees counter-clockwise) More...
 
QgsVector rotateBy (double rot) const
 Rotates the vector by a specified angle. More...
 
double x () const
 Returns the vector's x-component. More...
 
double y () const
 Returns the vector's y-component. More...
 

Detailed Description

A class to represent a vector.

Currently no Z axis / 2.5D support is implemented.

Definition at line 26 of file qgsvector.h.

Constructor & Destructor Documentation

◆ QgsVector() [1/2]

QgsVector::QgsVector ( )

Default constructor for QgsVector.

Creates a vector with length of 0.0.

Definition at line 21 of file qgsvector.cpp.

◆ QgsVector() [2/2]

QgsVector::QgsVector ( double  x,
double  y 
)

Constructor for QgsVector taking x and y component values.

Parameters
xx-component
yy-component

Definition at line 27 of file qgsvector.cpp.

Member Function Documentation

◆ angle() [1/2]

double QgsVector::angle ( ) const

Returns the angle of the vector in radians.

Definition at line 97 of file qgsvector.cpp.

◆ angle() [2/2]

double QgsVector::angle ( QgsVector  v) const

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

Definition at line 103 of file qgsvector.cpp.

◆ length()

double QgsVector::length ( ) const

Returns the length of the vector.

Definition at line 77 of file qgsvector.cpp.

◆ normalized()

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.

Definition at line 115 of file qgsvector.cpp.

◆ operator!=()

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

Inequality operator.

Definition at line 132 of file qgsvector.cpp.

◆ operator*() [1/2]

QgsVector QgsVector::operator* ( double  scalar) const

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

Parameters
scalarfactor to multiply by

Definition at line 38 of file qgsvector.cpp.

◆ operator*() [2/2]

double QgsVector::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.

Definition at line 48 of file qgsvector.cpp.

◆ operator+()

QgsVector QgsVector::operator+ ( QgsVector  other) const

Adds another vector to this vector.

Since
QGIS 3.0

Definition at line 53 of file qgsvector.cpp.

◆ operator+=()

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

Adds another vector to this vector in place.

Since
QGIS 3.0

Definition at line 58 of file qgsvector.cpp.

◆ operator-() [1/2]

QgsVector QgsVector::operator- ( ) const

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

Definition at line 33 of file qgsvector.cpp.

◆ operator-() [2/2]

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

Subtracts another vector to this vector.

Since
QGIS 3.0

Definition at line 65 of file qgsvector.cpp.

◆ operator-=()

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

Subtracts another vector to this vector in place.

Since
QGIS 3.0

Definition at line 70 of file qgsvector.cpp.

◆ operator/()

QgsVector QgsVector::operator/ ( double  scalar) const

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

Parameters
scalarfactor to divide by

Definition at line 43 of file qgsvector.cpp.

◆ operator==()

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

Equality operator.

Definition at line 127 of file qgsvector.cpp.

◆ perpVector()

QgsVector QgsVector::perpVector ( ) const

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

Definition at line 92 of file qgsvector.cpp.

◆ rotateBy()

QgsVector QgsVector::rotateBy ( double  rot) const

Rotates the vector by a specified angle.

Parameters
rotangle in radians

Definition at line 108 of file qgsvector.cpp.

◆ x()

double QgsVector::x ( ) const

Returns the vector's x-component.

See also
y()

Definition at line 82 of file qgsvector.cpp.

◆ y()

double QgsVector::y ( ) const

Returns the vector's y-component.

See also
x()

Definition at line 87 of file qgsvector.cpp.


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