From 3e44f949211bb259fdf8887c85a62c29a5185bda Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 9 Feb 2014 01:02:56 +0100 Subject: Introduce coordinate converter tool --- src/convertcoords.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/convertcoords.c (limited to 'src/convertcoords.c') 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 @@ +#include +#include +#include +int main(int argc, char *argv[]) +{ + double x = atof(argv[1]); + double y = atof(argv[2]); + + double R = 6365000; + double fe = 5200000; + double fn = 1200000; + double ph0 = 0.5235977; // 30deg + double ph1 = 0.7853980; // 45deg + double ph2 = 0.9599309; // 55deg + double l0 = 0.1745329; // 10deg + + double xs = (x-fe)/R; + double ys = (y-fn)/R; + double ph0_s = 0.25*M_PI+0.5*ph0; + double ph1_s = 0.25*M_PI+0.5*ph1; + double ph2_s = 0.25*M_PI+0.5*ph2; + + double n = log(cos(ph1)/cos(ph2))/log(tan(ph2_s)/tan(ph1_s)); + double F = cos(ph1)*pow(tan(ph1_s),n)/n; + double r0 = F / pow(tan(ph0_s),n); + double r = sqrt(pow(xs,2)+pow(r0-ys,2)); + double th = atan(xs/(r0-ys)); + + double lon = l0+th/n; + double lat = 2.0*atan(pow(F/r,1.0/n))-0.5*M_PI; + + printf("%f %f", lat*180.0/M_PI, lon*180.0/M_PI); + return 0; +} -- cgit v1.2.3