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