QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
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 : matthias@opengis.ch
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
24
using namespace
Qt::StringLiterals;
25
26
QgsVector
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
33
QgsVector
QgsVector::normalized
()
const
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
}
QgsException
Defines a QGIS exception class.
Definition
qgsexception.h:34
QgsVector::normalized
QgsVector normalized() const
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1....
Definition
qgsvector.cpp:33
QgsVector::angle
double angle() const
Returns the angle of the vector in radians.
Definition
qgsvector.h:171
QgsVector::rotateBy
QgsVector rotateBy(double rot) const
Rotates the vector by a specified angle.
Definition
qgsvector.cpp:26
QgsVector::QgsVector
QgsVector()=default
Default constructor for QgsVector.
QgsVector::length
double length() const
Returns the length of the vector.
Definition
qgsvector.h:127
qgis.h
qgsexception.h
qgsvector.h
Generated on
for QGIS API Documentation by
1.17.0