-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathgeosphere.h
54 lines (41 loc) · 2.03 KB
/
geosphere.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2018-2025 Robert J. Hijmans
//
// This file is part of the "spat" library.
//
// spat is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// spat is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with spat. If not, see <http://www.gnu.org/licenses/>.
//double distance_cos(const double &lon1, const double &lat1, const double &lon2, const double &lat2, const double &r = 6378137);
inline void deg2rad(std::vector<double> &x) {
const double f = 0.0174532925199433;
for (double& d : x) d *= f;
}
inline void deg2rad(double &x) {
const double f = 0.0174532925199433;
x *= f;
}
inline double distance_cos(double lon1, double lat1, double lon2, double lat2) {
const double r = 6378137.;
return r * acos((sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon1-lon2)));
}
inline double distance_hav(double lon1, double lat1, double lon2, double lat2) {
const double r = 6378137.;
double dLat = lat2-lat1;
double dLon = lon2-lon1;
double a = sin(dLat/2.) * sin(dLat/2.) + cos(lat1) * cos(lat2) * sin(dLon/2.) * sin(dLon/2.);
return 2. * atan2(sqrt(a), sqrt(1. - a)) * r;
}
double distance_geo(double lon1, double lat1, double lon2, double lat2);
double direction_cos(double& lon1, double& lat1, double& lon2, double& lat2);
double dist2segment_hav(double plon, double plat, double lon1, double lat1, double lon2, double lat2, double r=6378137.);
double dist2segment_cos(double plon, double plat, double lon1, double lat1, double lon2, double lat2, double r=6378137.);
double dist2segment_geo(double plon, double plat, double lon1, double lat1, double lon2, double lat2, double notused=0.);