2 * Copyright (C) 2009-2011 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 gdouble (*GritsPoints)[3];
166 typedef struct _GritsBounds GritsBounds;
167 struct _GritsBounds {
171 void grits_bounds_set_bounds(GritsBounds *bounds,
172 gdouble n, gdouble s, gdouble e, gdouble w);
181 * Used by GritsOpenGL to set up the drawing window
183 #define FOV_DIST (1039.23)
187 * @dist: the distance between the eye and the point in question
189 * Get the resolution that a point would be drawn at on the screen
191 * Returns: the resolution in meters per pixel
193 #define MPPX(dist) (dist/FOV_DIST)
195 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
196 gdouble *x, gdouble *y, gdouble *z);
198 void xyz2lle(gdouble x, gdouble y, gdouble z,
199 gdouble *lat, gdouble *lon, gdouble *elev);
201 void xyz2ll(gdouble x, gdouble y, gdouble z,
202 gdouble *lat, gdouble *lon);
204 gdouble ll2m(gdouble lon_dist, gdouble lat);
206 gdouble distd(gdouble *a, gdouble *b);
208 void crossd(gdouble *a, gdouble *b, gdouble *out);
210 void crossd3(gdouble *a, gdouble *b, gdouble *c, gdouble *out);
212 gdouble lengthd(gdouble *a);
214 void normd(gdouble *a);
216 gdouble lon_avg(gdouble a, gdouble b);
218 GritsPoints *parse_points(const gchar *string,
219 const gchar *group_sep, const gchar *point_sep, const gchar *coord_sep,
220 GritsBounds *bounds, GritsPoint *center);
222 void free_points(GritsPoints *points);