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/>.
26 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
27 gdouble *x, gdouble *y, gdouble *z)
29 gdouble rad = elev2rad(elev);
30 gdouble azim = lon2azim(lon);
31 gdouble incl = lat2incl(lat);
32 *z = rad * cos(azim) * sin(incl);
33 *x = rad * sin(azim) * sin(incl);
37 void xyz2lle(gdouble x, gdouble y, gdouble z,
38 gdouble *lat, gdouble *lon, gdouble *elev)
40 gdouble rad = sqrt(x*x + y*y + z*z);
41 *lat = incl2lat(acos(y / rad));
42 *lon = azim2lon(atan2(x,z));
43 *elev = rad2elev(rad);
46 void xyz2ll(gdouble x, gdouble y, gdouble z,
47 gdouble *lat, gdouble *lon)
49 gdouble rad = sqrt(x*x + y*y + z*z);
50 *lat = incl2lat(acos(y / rad));
51 *lon = azim2lon(atan2(x,z));
54 gdouble ll2m(gdouble lon_dist, gdouble lat)
56 gdouble azim = (-lat+90)/180*M_PI;
57 gdouble rad = sin(azim) * EARTH_R;
58 gdouble circ = 2 * M_PI * rad;
59 return lon_dist/360 * circ;
62 gdouble distd(gdouble *a, gdouble *b)
64 return sqrt((a[0]-b[0])*(a[0]-b[0]) +
65 (a[1]-b[1])*(a[1]-b[1]) +
66 (a[2]-b[2])*(a[2]-b[2]));
69 gdouble lon_avg(gdouble a, gdouble b)
71 gdouble diff = ABS(a-b);
72 gdouble avg = (a+b)/2;