QGIS API Documentation  3.20.0-Odense (decaadbb31)
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
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
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 
21 QgsVector QgsVector::rotateBy( double rot ) const
22 {
23  double angle = std::atan2( mY, mX ) + rot;
24  double len = length();
25  return QgsVector( len * std::cos( angle ), len * std::sin( angle ) );
26 }
27 
29 {
30  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.
Definition: qgsexception.h:35
A class to represent a vector.
Definition: qgsvector.h:30
QgsVector normalized() const SIP_THROW(QgsException)
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1....
Definition: qgsvector.cpp:28
QgsVector rotateBy(double rot) const SIP_HOLDGIL
Rotates the vector by a specified angle.
Definition: qgsvector.cpp:21
double angle() const SIP_HOLDGIL
Returns the angle of the vector in radians.
Definition: qgsvector.h:172
QgsVector()=default
Default constructor for QgsVector.
double length() const SIP_HOLDGIL
Returns the length of the vector.
Definition: qgsvector.h:128