34 return QgsVector( mX * scalar, mY * scalar );
39 return *
this * ( 1.0 / scalar );
44 return mX * v.mX + mY * v.mY;
49 return QgsVector( mX + other.mX, mY + other.mY );
61 return QgsVector( mX - other.mX, mY - other.mY );
73 return std::sqrt( mX * mX + mY * mY );
93 double angle = std::atan2( mY, mX );
94 return angle < 0.0 ? angle + 2.0 * M_PI :
angle;
104 return mX * v.
y() - mY * v.
x();
109 double angle = std::atan2( mY, mX ) + rot;
111 return QgsVector( len * std::cos( angle ), len * std::sin( angle ) );
120 throw QgsException( QStringLiteral(
"normalized vector of null vector undefined" ) );
bool operator!=(QgsVector other) const
Inequality operator.
QgsVector rotateBy(double rot) const
Rotates the vector by a specified angle.
QgsVector & operator+=(QgsVector other)
Adds another vector to this vector in place.
bool operator==(QgsVector other) const
Equality operator.
QgsVector operator+(QgsVector other) const
Adds another vector to this vector.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double y() const
Returns the vector's y-component.
double angle() const
Returns the angle of the vector in radians.
QgsVector perpVector() const
Returns the perpendicular vector to this vector (rotated 90 degrees counter-clockwise) ...
QgsVector operator-() const
Swaps the sign of the x and y components of the vector.
QgsVector normalized() const
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1.0).
A class to represent a vector.
double length() const
Returns the length of the vector.
QgsVector operator*(double scalar) const
Returns a vector where the components have been multiplied by a scalar value.
QgsVector & operator-=(QgsVector other)
Subtracts another vector to this vector in place.
double crossProduct(QgsVector v) const
Returns the 2D cross product of this vector and another vector v.
double x() const
Returns the vector's x-component.
QgsVector operator/(double scalar) const
Returns a vector where the components have been divided by a scalar value.
Defines a QGIS exception class.
QgsVector()=default
Default constructor for QgsVector.