libs
UavDynamics
src
math
geodetic.cpp
Go to the documentation of this file.
1
/*
2
* This program is free software: you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation, version 3.
5
*
6
* This program is distributed in the hope that it will be useful, but
7
* WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9
* General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program. If not, see <http://www.gnu.org/licenses/>.
13
*
14
* Author: Dmitry Ponomarev <ponomarevda96@gmail.com>
15
*/
16
17
#include "
UavDynamics/math/geodetic.hpp
"
18
#include <cmath>
19
20
// Constants
21
static
const
double
a
= 6378137.0;
// WGS-84 Earth semimajor axis (m)
22
static
const
double
f
= 1.0 / 298.257223563;
// WGS-84 flattening
23
static
const
double
b
=
a
* (1 -
f
);
// Semi-minor axis
24
static
const
double
e_sq
=
f
* (2 -
f
);
// Square of eccentricity
25
26
27
CoordinateConverter::CoordinateConverter
() : ref_lat_deg(0), ref_lon_deg(0), ref_alt_meters(0) {}
28
29
void
CoordinateConverter::setInitialValues
(
double
lat_deg,
double
lon_deg,
double
alt_meters) {
30
ref_lat_deg
= lat_deg;
31
ref_lon_deg
= lon_deg;
32
ref_alt_meters
= alt_meters;
33
34
// Precompute cos and sin of latitude and longitude for efficiency
35
cos_lat
= cos(
degreesToRadians
(lat_deg));
36
}
37
38
void
CoordinateConverter::enuToGeodetic
(
39
double
local_enu_x_meters,
double
local_enu_y_meters,
double
local_enu_z_meters,
40
double
* lat_deg,
double
* lon_deg,
double
* alt_meters)
const
{
41
double
dlat = (local_enu_y_meters /
earthRadiusMeters
()) * (180.0 / M_PI);
42
double
dlon = (local_enu_x_meters / (
earthRadiusMeters
() *
cos_lat
)) * (180.0 / M_PI);
43
double
dalt = local_enu_z_meters;
44
45
*lat_deg =
ref_lat_deg
+ dlat;
46
*lon_deg =
ref_lon_deg
+ dlon;
47
*alt_meters =
ref_alt_meters
+ dalt;
48
}
49
50
double
CoordinateConverter::degreesToRadians
(
double
degrees)
const
{
51
return
degrees * M_PI / 180.0;
52
}
53
54
double
CoordinateConverter::earthRadiusMeters
()
const
{
55
return
6378137.0;
// WGS-84 Earth radius in meters
56
}
CoordinateConverter::degreesToRadians
double degreesToRadians(double degrees) const
Definition:
geodetic.cpp:50
a
static const double a
Definition:
geodetic.cpp:21
CoordinateConverter::cos_lat
double cos_lat
Definition:
geodetic.hpp:42
b
static const double b
Definition:
geodetic.cpp:23
CoordinateConverter::CoordinateConverter
CoordinateConverter()
Definition:
geodetic.cpp:27
geodetic.hpp
CoordinateConverter::earthRadiusMeters
double earthRadiusMeters() const
Definition:
geodetic.cpp:54
CoordinateConverter::ref_lon_deg
double ref_lon_deg
Definition:
geodetic.hpp:38
CoordinateConverter::ref_lat_deg
double ref_lat_deg
Definition:
geodetic.hpp:37
e_sq
static const double e_sq
Definition:
geodetic.cpp:24
CoordinateConverter::setInitialValues
void setInitialValues(double lat, double lon, double alt)
Definition:
geodetic.cpp:29
CoordinateConverter::ref_alt_meters
double ref_alt_meters
Definition:
geodetic.hpp:39
CoordinateConverter::enuToGeodetic
void enuToGeodetic(double enu_x, double enu_y, double enu_z, double *lat, double *lon, double *alt) const
Definition:
geodetic.cpp:38
f
static const double f
Definition:
geodetic.cpp:22
inno_vtol_dynamics
Author(s): Roman Fedorenko, Dmitry Ponomarev, Ezra Tal, Winter Guerra
autogenerated on Mon Dec 9 2024 03:13:35