QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
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 *
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
19#include "qgis.h"
20#include "qgsexception.h"
21
22QgsVector QgsVector::rotateBy( double rot ) const
23{
24 const double angle = std::atan2( mY, mX ) + rot;
25 const double len = length();
26 return QgsVector( len * std::cos( angle ), len * std::sin( angle ) );
27}
28
30{
31 const double len = length();
32
33 if ( len == 0.0 )
34 {
35 throw QgsException( QStringLiteral( "normalized vector of null vector undefined" ) );
36 }
37
38 return *this / len;
39}
Defines a QGIS exception class.
QgsVector normalized() const
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1....
Definition qgsvector.cpp:29
double angle() const
Returns the angle of the vector in radians.
Definition qgsvector.h:169
QgsVector rotateBy(double rot) const
Rotates the vector by a specified angle.
Definition qgsvector.cpp:22
QgsVector()=default
Default constructor for QgsVector.
double length() const
Returns the length of the vector.
Definition qgsvector.h:125