]> Pileus Git - grits/blob - src/gis-util.h
Rename GisBBox to GisBounds
[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  * Datatypes *
151  *************/
152
153 /* GisPoint */
154 typedef struct _GisPoint GisPoint;
155 struct _GisPoint {
156         gdouble lat, lon, elev;
157 };
158
159 void gis_point_set_lle(GisPoint *point,
160                 gdouble lat, gdouble lon, gdouble elev);
161
162 /* GisBounds */
163 typedef struct _GisBounds GisBounds;
164 struct _GisBounds {
165         gdouble n, s, e, w;
166 };
167
168 void gis_bounds_set_bounds(GisBounds *bounds,
169                 gdouble n, gdouble s, gdouble e, gdouble w);
170
171
172 /********
173  * Misc *
174  ********/
175 /**
176  * FOV_DIST:
177  *
178  * Used by GisOpenGL to set up the drawing window
179  */
180 #define FOV_DIST   2000.0
181
182 /**
183  * MPPX:
184  * @dist: the distance between the eye and the point in question
185  *
186  * Get the resolution that a point would be drawn at on the screen
187  *
188  * Returns: the resolution in meters per pixel
189  */
190 #define MPPX(dist) (4*dist/FOV_DIST)
191
192 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
193                 gdouble *x, gdouble *y, gdouble *z);
194
195 void xyz2lle(gdouble x, gdouble y, gdouble z,
196                 gdouble *lat, gdouble *lon, gdouble *elev);
197
198 void xyz2ll(gdouble x, gdouble y, gdouble z,
199                 gdouble *lat, gdouble *lon);
200
201 gdouble ll2m(gdouble lon_dist, gdouble lat);
202
203 gdouble distd(gdouble *a, gdouble *b);
204
205 gdouble lon_avg(gdouble a, gdouble b);
206
207 #endif