]> Pileus Git - grits/blob - src/gis-util.h
c7838966709f9c74f8cb5a3de23b54f9b486280f
[grits] / src / gis-util.h
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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 #include <glib.h>
22
23 /**
24  * EARTH_R:
25  *
26  * Radius of the earth
27  */
28 #define EARTH_R (6371000)
29
30 /**
31  * EARTH_C:
32  *
33  * Circumference of the earth at the equator
34  */
35 #define EARTH_C (2*G_PI*EARTH_R)
36
37 /**
38  * NORTH:
39  *
40  * Latitude at the north poll
41  */
42 #define NORTH  90
43
44 /**
45  * SOUTH:
46  *
47  * Latitude at the south poll
48  */
49 #define SOUTH -90
50
51 /**
52  * EAST:
53  *
54  * Eastern most longitude
55  */
56 #define EAST  180
57
58 /**
59  * WEST:
60  *
61  * Western most longitude
62  */
63 #define WEST -180
64
65 /***************
66  * Conversions *
67  ***************/
68 /**
69  * azim2lon:
70  * @azim: the azimuth in radians
71  *
72  * Convert azimuth to longitude
73  *
74  * Returns: the longitude 
75  */
76 #define azim2lon(azim) ((azim)*180/G_PI)
77
78 /**
79  * lon2azim:
80  * @lon: the longitude
81  *
82  * Convert longitude to azimuth 
83  *
84  * Returns: the azimuth in radians
85  */
86 #define lon2azim(lon)  ((lon)*G_PI/180)
87
88 /**
89  * incl2lat:
90  * @incl: the inclination in radians
91  *
92  * Convert inclination to latitude
93  *
94  * Returns: the latitude
95  */
96 #define incl2lat(incl) (90-(incl)*180/G_PI)
97
98 /**
99  * lat2incl:
100  * @lat: the latitude
101  *
102  * Convert latitude to inclination
103  *
104  * Returns: the inclination in radians
105  */
106 #define lat2incl(lat)  ((90-(lat))*G_PI/180)
107
108 /**
109  * rad2elev:
110  * @rad: the radius in meters
111  *
112  * Convert radius to elevation
113  *
114  * Returns: the elevation in meters above the earth surface
115  */
116 #define rad2elev(rad)  ((rad)-EARTH_R)
117
118 /**
119  * elev2rad:
120  * @elev: the elevation in meters above the earth surface
121  *
122  * Convert elevation to radius
123  *
124  * Returns: the radius in meters
125  */
126 #define elev2rad(elev) ((elev)+EARTH_R)
127
128 /**
129  * deg2rad:
130  * @deg: the angle in degrees
131  *
132  * Convert degrees to radians
133  *
134  * Returns: the angle in radians
135  */
136 #define deg2rad(deg) (((deg)*G_PI)/180.0)
137
138 /**
139  * rad2deg:
140  * @rad: the angle in radians
141  *
142  * Convert radians to degrees
143  *
144  * Returns: the angle in degrees
145  */
146 #define rad2deg(rad) (((rad)*180.0)/G_PI)
147
148
149 /********
150  * Misc *
151  ********/
152 /**
153  * FOV_DIST:
154  *
155  * Used by GisOpenGL to set up the drawing window
156  */
157 #define FOV_DIST   2000.0
158
159 /**
160  * MPPX:
161  * @dist: the distance between the eye and the point in question
162  *
163  * Get the resolution that a point would be drawn at on the screen
164  *
165  * Returns: the resolution in meters per pixel
166  */
167 #define MPPX(dist) (4*dist/FOV_DIST)
168
169 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
170                 gdouble *x, gdouble *y, gdouble *z);
171
172 void xyz2lle(gdouble x, gdouble y, gdouble z,
173                 gdouble *lat, gdouble *lon, gdouble *elev);
174
175 void xyz2ll(gdouble x, gdouble y, gdouble z,
176                 gdouble *lat, gdouble *lon);
177
178 gdouble ll2m(gdouble lon_dist, gdouble lat);
179
180 gdouble distd(gdouble *a, gdouble *b);
181
182 gdouble lon_avg(gdouble a, gdouble b);
183
184 #endif