2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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.
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.
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/>.
18 #ifndef __GRITS_UTIL_H__
19 #define __GRITS_UTIL_H__
28 #define EARTH_R (6371000)
33 * Circumference of the earth at the equator
35 #define EARTH_C (2*G_PI*EARTH_R)
40 * Latitude at the north poll
47 * Latitude at the south poll
54 * Eastern most longitude
61 * Western most longitude
70 * @azim: the azimuth in radians
72 * Convert azimuth to longitude
74 * Returns: the longitude
76 #define azim2lon(azim) ((azim)*180/G_PI)
82 * Convert longitude to azimuth
84 * Returns: the azimuth in radians
86 #define lon2azim(lon) ((lon)*G_PI/180)
90 * @incl: the inclination in radians
92 * Convert inclination to latitude
94 * Returns: the latitude
96 #define incl2lat(incl) (90-(incl)*180/G_PI)
102 * Convert latitude to inclination
104 * Returns: the inclination in radians
106 #define lat2incl(lat) ((90-(lat))*G_PI/180)
110 * @rad: the radius in meters
112 * Convert radius to elevation
114 * Returns: the elevation in meters above the earth surface
116 #define rad2elev(rad) ((rad)-EARTH_R)
120 * @elev: the elevation in meters above the earth surface
122 * Convert elevation to radius
124 * Returns: the radius in meters
126 #define elev2rad(elev) ((elev)+EARTH_R)
130 * @deg: the angle in degrees
132 * Convert degrees to radians
134 * Returns: the angle in radians
136 #define deg2rad(deg) (((deg)*G_PI)/180.0)
140 * @rad: the angle in radians
142 * Convert radians to degrees
144 * Returns: the angle in degrees
146 #define rad2deg(rad) (((rad)*180.0)/G_PI)
154 typedef struct _GritsPoint GritsPoint;
156 gdouble lat, lon, elev;
159 void grits_point_set_lle(GritsPoint *point,
160 gdouble lat, gdouble lon, gdouble elev);
163 typedef struct _GritsBounds GritsBounds;
164 struct _GritsBounds {
168 void grits_bounds_set_bounds(GritsBounds *bounds,
169 gdouble n, gdouble s, gdouble e, gdouble w);
178 * Used by GritsOpenGL to set up the drawing window
180 #define FOV_DIST 2000.0
184 * @dist: the distance between the eye and the point in question
186 * Get the resolution that a point would be drawn at on the screen
188 * Returns: the resolution in meters per pixel
190 #define MPPX(dist) (4*dist/FOV_DIST)
192 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
193 gdouble *x, gdouble *y, gdouble *z);
195 void xyz2lle(gdouble x, gdouble y, gdouble z,
196 gdouble *lat, gdouble *lon, gdouble *elev);
198 void xyz2ll(gdouble x, gdouble y, gdouble z,
199 gdouble *lat, gdouble *lon);
201 gdouble ll2m(gdouble lon_dist, gdouble lat);
203 gdouble distd(gdouble *a, gdouble *b);
205 gdouble lon_avg(gdouble a, gdouble b);