summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2014-02-09 01:02:56 +0100
committerDirk Engling <erdgeist@erdgeist.org>2014-02-09 01:02:56 +0100
commit3e44f949211bb259fdf8887c85a62c29a5185bda (patch)
tree14c2178d18287867849d25eb1bde773b5c70fc95 /src
parenta90b5e42599f20c91cab02025cb69df79efd10dc (diff)
Introduce coordinate converter tool
Diffstat (limited to 'src')
-rw-r--r--src/convertcoords.c34
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>
4int 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}