-
Notifications
You must be signed in to change notification settings - Fork 5
/
GenGeomAlgs.h
99 lines (90 loc) · 3.74 KB
/
GenGeomAlgs.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* GeoDa TM, Copyright (C) 2011-2015 by Luc Anselin - all rights reserved
*
* This file is part of GeoDa.
*
* GeoDa 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 3 of the License, or
* (at your option) any later version.
*
* GeoDa 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Fhe following functions: findArea and ComputeArea2D
* are borrowed from FastArea.c++
*
* From the paper:
*
* Daniel Sunday
* "Fast Polygon Area and Newell Normal Computation"
* journal of graphics tools, 7(2):9-13, 2002
*
*/
#ifndef __GEODA_CENTER_GEN_GEOM_ALGS_H__
#define __GEODA_CENTER_GEN_GEOM_ALGS_H__
namespace GenGeomAlgs {
const double pi = 3.141592653589793238463;
const double pi_x_2 = pi*2.0;
const double pi_x_1_5 = pi*1.5;
const double pi_ovr_2 = pi/2.0;
const double d180_ovr_pi = 180.0/pi;
const double pi_ovr_180 = pi/180.0;
const double one_mi_in_km = 1.609344; // 1 Statute mi in km
const double earth_radius_km = 6371.0;
const double earth_radius_mi = earth_radius_km / one_mi_in_km;
double DegToRad(double deg);
double RadToDeg(double rad);
double NormLonDeg(double lon);
double NormLonRad(double lon);
double NormLatDeg(double lat);
double NormLatRad(double lat);
void LongLatDegToUnit(const double& lon, const double& lat,
double& x, double& y, double& z);
void LongLatRadToUnit(const double& lon, const double& lat,
double& x, double& y, double& z);
void UnitToLongLatDeg(const double& x, const double& y, const double& z,
double& lon, double& lat);
void UnitToLongLatRad(const double& x, const double& y, const double& z,
double& lon, double& lat);
/** Convert unit sphere euclidean distance to radians. */
double UnitDistToRad(double d);
double UnitDistToDeg(double d);
/** Convert radians to straight-line euclidean distance on unit sphere. */
double RadToUnitDist(double r);
double DegToUnitDist(double r);
/** Limit angle to between 0 and pi radians (shortest distance
* around circle). */
double ShortestRad(double r);
/** Limit angle to between 0 and 180 radians (shortest distance
* around circle). */
double ShortestDeg(double d);
double ComputeEucDist(double x1, double y1, double x2, double y2);
double ComputeArcDistMi(double lon1, double lat1, double lon2, double lat2);
double ComputeArcDistKm(double lon1, double lat1, double lon2, double lat2);
double ComputeArcDistRad(double lon1, double lat1, double lon2, double lat2);
double LonLatRadDistRad(double lon1, double lat1, double lon2, double lat2);
double ComputeArcDistDeg(double lon1, double lat1, double lon2, double lat2);
double EarthRadToKm(double radians);
double EarthRadToMi(double radians);
double EarthKmToRad(double d);
double EarthMiToRad(double d);
double ComputePerimeter2D(int n, double *x, double *y);
double ComputeArea2D(int n, double *x, double *y); // output unit normal
double findArea(int n, double *x, double *y); // 2D polygon
bool ClipToBB(double& x0, double& y0, double& x1, double& y1,
const double& xmin, const double& ymin,
const double& xmax, const double& ymax);
bool ExtendRayToBB(double x0, double y0, double x1, double y1,
double& x2, double& y2,
const double xmin, const double ymin,
const double xmax, const double ymax);
bool nearlyEqual(double x, double y);
}
#endif