]> Pileus Git - grits/blob - src/gis-util.h
cf3b09faf9189ad57b93b581df81b68958d2fd8c
[grits] / src / gis-util.h
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __GIS_UTIL_H__
19 #define __GIS_UTIL_H__
20
21 #define EARTH_R (6371000)
22 #define EARTH_C (2*G_PI*EARTH_R)
23 #define NORTH  90
24 #define SOUTH -90
25 #define EAST  180
26 #define WEST -180
27
28 /**
29  * Terms
30  * -----
31  * deg    - Degrees
32  * rad    - Radians, also radius
33  * m      - Meters, for earth-based distances
34  * px     - Pixels, for screen-based distances
35  *
36  * height - Height, the distance above the geoid (ground)
37  * elev   - Elevation, the distance above the spheroid
38  * rad    - Radius, the distance from the center of the earth
39  *
40  * lat    - Latitude, amount north-south, -90 (S) .. 90 (N)
41  * lon    - Longitude, amount east-west, -180 (W) .. 180 (E)
42  * incl   - Inclination, polar equiv of  latitude, Pi .. 0
43  * azim   - Azimuth, polar equiv of longitude, -Pi .. Pi
44  *
45  * x      -  0° lon is positive
46  * y      - 90° lon is positive
47  * z      - North pole is positive
48  *
49  * llh    - lat,lon,height
50  * lle    - lat,lon,elev
51  * llr    - lat,lon,rad
52  * pol    - incl,azim,rad
53  * xyz    - x,y,z
54  */
55
56 /**
57  *             lat    lon   elev ->      x      y      z
58  * lle2xyz:    0.0,   0.0,   0.0 ->    0.0,   0.0,  10.0
59  * lle2xyz:   90.0,   0.0,   0.0 ->    0.0,  10.0,   0.0
60  * lle2xyz:    0.0,  90.0,   0.0 ->   10.0,   0.0,   0.0
61  *
62  *               x      y      z ->    lat    lon   elev
63  * xyz2lle:   10.0,   0.0,   0.0 ->    0.0,  90.0,   0.0
64  * xyz2lle:    0.0,  10.0,   0.0 ->   90.0,   0.0,   0.0
65  * xyz2lle:    0.0,   0.0,  10.0 ->    0.0,   0.0,   0.0
66  */
67
68 #define azim2lon(azim) ((azim)*180/G_PI)
69 #define lon2azim(lon)  ((lon)*G_PI/180)
70 #define incl2lat(incl) (90-(incl)*180/G_PI)
71 #define lat2incl(lat)  ((90-(lat))*G_PI/180)
72 #define rad2elev(rad)  ((rad)-EARTH_R)
73 #define elev2rad(elev) ((elev)+EARTH_R)
74
75 #define deg2rad(deg) (((deg)*G_PI)/180.0)
76 #define rad2deg(rad) (((rad)*180.0)/G_PI)
77
78 #define FOV_DIST   2000.0
79 #define MPPX(dist) (4*dist/FOV_DIST)
80
81 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
82                 gdouble *x, gdouble *y, gdouble *z);
83
84 void xyz2lle(gdouble x, gdouble y, gdouble z,
85                 gdouble *lat, gdouble *lon, gdouble *elev);
86
87 void xyz2ll(gdouble x, gdouble y, gdouble z,
88                 gdouble *lat, gdouble *lon);
89
90 gdouble ll2m(gdouble lon_dist, gdouble lat);
91
92 gdouble distd(gdouble *a, gdouble *b);
93
94 gdouble lon_avg(gdouble a, gdouble b);
95
96 #endif