rd.c - randomcrap - random crap programs of varying quality
 (HTM) git clone git://git.codemadness.org/randomcrap
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       rd.c (1561B)
       ---
            1 #include <stdio.h>
            2 
            3 /* "Rijksdriehoek" to WGS84 (lat, lon) coordinate.
            4    "Benaderingsformules voor de transformatie tussen RD- en WGS84-kaartcoordinaten" - https://docplayer.nl/7261923-a.html */
            5 void
            6 rd2latlon(int x, int y, double *lat, double *lon)
            7 {
            8         /* Central reference point "Rijksdriehoek" coordinate:
            9            "Onze Lieve Vrouwetoren ('Lange Jan') in Amersfoort */
           10         int refrdx = 155000;
           11         int refrdy = 463000;
           12 
           13         double dx = (double)(x - refrdx) * 0.000010;
           14         double dy = (double)(y - refrdy) * 0.000010;
           15 
           16         /* reduce duplicate calculations and don't use -lm */
           17         double px2 = dx * dx;
           18         double py2 = dy * dy;
           19         double px3 = px2 * dx;
           20         double py3 = py2 * dy;
           21         double px4 = px3 * dx;
           22         double py4 = py3 * dy;
           23         double px5 = px4 * dx;
           24 
           25         double sumn = 
           26                 (3235.65389 * dy) + 
           27                 (-32.58297 * px2) + 
           28                 (-0.2475 * py2) + 
           29                 (-0.84978 * px2 * dy) + 
           30                 (-0.0655 * py3) + 
           31                 (-0.01709 * px2 * py2) + 
           32                 (-0.00738 * dx) + 
           33                 (0.0053 * px4) + 
           34                 (-0.00039 * px2 * py3) + 
           35                 (0.00033 * px4 * dy) + 
           36                 (-0.00012 * dx * dy);
           37         double sume = 
           38                 (5260.52916 * dx) + 
           39                 (105.94684 * dx * dy) + 
           40                 (2.45656 * dx * py2) + 
           41                 (-0.81885 * px3) + 
           42                 (0.05594 * dx * px3) + 
           43                 (-0.05607 * px3 * dy) + 
           44                 (0.01199 * dy) + 
           45                 (-0.00256 * px3 * py2) + 
           46                 (0.00128 * dx * py4) + 
           47                 (0.00022 * py2) + 
           48                 (-0.00022 * px2) + 
           49                 (0.00026 * px5);
           50 
           51         /* (lat, lon) reference point WGS84 coordinate. */
           52         *lat = 52.15517 + (sumn / 3600);
           53         *lon = 5.387206 + (sume / 3600);
           54 }
           55 
           56 int
           57 main(void)
           58 {
           59         double lat, lon;
           60 
           61         rd2latlon(122202, 487250, &lat, &lon);
           62 
           63         printf("%.17g, %.17g\n", lat, lon);
           64 
           65         return 0;
           66 }