QGIS API Documentation 3.39.0-Master (fa961c7b5bb)
Searching...
No Matches
qgsvector.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvector.cpp - QgsVector
3
4 ---------------------
5 begin : 24.2.2017
6 copyright : (C) 2017 by Matthias Kuhn
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#include "qgsvector.h"
18#include "qgis.h"
19#include "qgsexception.h"
20
21QgsVector QgsVector::rotateBy( double rot ) const
22{
23 const double angle = std::atan2( mY, mX ) + rot;
24 const double len = length();
25 return QgsVector( len * std::cos( angle ), len * std::sin( angle ) );
26}
27
29{
30 const double len = length();
31
32 if ( len == 0.0 )
33 {
34 throw QgsException( QStringLiteral( "normalized vector of null vector undefined" ) );
35 }
36
37 return *this / len;
38}
Defines a QGIS exception class.
A class to represent a vector.
Definition qgsvector.h:30
QgsVector normalized() const
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1....
Definition qgsvector.cpp:28
double angle() const
Returns the angle of the vector in radians.
Definition qgsvector.h:168
QgsVector rotateBy(double rot) const
Rotates the vector by a specified angle.
Definition qgsvector.cpp:21
QgsVector()=default
Default constructor for QgsVector.
double length() const
Returns the length of the vector.
Definition qgsvector.h:124