QGIS API Documentation 3.99.0-Master (d270888f95f)
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
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
26QgsVector QgsVector::rotateBy( double rot ) const
27{
28 const double angle = std::atan2( mY, mX ) + rot;
29 const double len = length();
30 return QgsVector( len * std::cos( angle ), len * std::sin( angle ) );
31}
32
34{
35 const double len = length();
36
37 if ( len == 0.0 )
38 {
39 throw QgsException( u"normalized vector of null vector undefined"_s );
40 }
41
42 return *this / len;
43}
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:33
double angle() const
Returns the angle of the vector in radians.
Definition qgsvector.h:172
QgsVector rotateBy(double rot) const
Rotates the vector by a specified angle.
Definition qgsvector.cpp:26
QgsVector()=default
Default constructor for QgsVector.
double length() const
Returns the length of the vector.
Definition qgsvector.h:128