diff options
| -rw-r--r-- | src/convertcoords.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/convertcoords.c b/src/convertcoords.c new file mode 100644 index 0000000..3297d8f --- /dev/null +++ b/src/convertcoords.c | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <math.h> | ||
| 4 | int main(int argc, char *argv[]) | ||
| 5 | { | ||
| 6 | double x = atof(argv[1]); | ||
| 7 | double y = atof(argv[2]); | ||
| 8 | |||
| 9 | double R = 6365000; | ||
| 10 | double fe = 5200000; | ||
| 11 | double fn = 1200000; | ||
| 12 | double ph0 = 0.5235977; // 30deg | ||
| 13 | double ph1 = 0.7853980; // 45deg | ||
| 14 | double ph2 = 0.9599309; // 55deg | ||
| 15 | double l0 = 0.1745329; // 10deg | ||
| 16 | |||
| 17 | double xs = (x-fe)/R; | ||
| 18 | double ys = (y-fn)/R; | ||
| 19 | double ph0_s = 0.25*M_PI+0.5*ph0; | ||
| 20 | double ph1_s = 0.25*M_PI+0.5*ph1; | ||
| 21 | double ph2_s = 0.25*M_PI+0.5*ph2; | ||
| 22 | |||
| 23 | double n = log(cos(ph1)/cos(ph2))/log(tan(ph2_s)/tan(ph1_s)); | ||
| 24 | double F = cos(ph1)*pow(tan(ph1_s),n)/n; | ||
| 25 | double r0 = F / pow(tan(ph0_s),n); | ||
| 26 | double r = sqrt(pow(xs,2)+pow(r0-ys,2)); | ||
| 27 | double th = atan(xs/(r0-ys)); | ||
| 28 | |||
| 29 | double lon = l0+th/n; | ||
| 30 | double lat = 2.0*atan(pow(F/r,1.0/n))-0.5*M_PI; | ||
| 31 | |||
| 32 | printf("%f %f", lat*180.0/M_PI, lon*180.0/M_PI); | ||
| 33 | return 0; | ||
| 34 | } | ||
