FreeWRL / FreeX3D 4.3.0
fwgeolib.cpp
1
2
3// wrapper for geographicLib by Karney
4/*
5Karney/geographicLib could be a good way to verify independently that I didn't break something
6From what I've read, Karney got accuracy in the nanometer range for UTM/GD GD/UTM
7- his recent ie 2010 methods are refered to by others as the best way
8- and he has a MIT lib with .hpp/.cpp (C++) conversions, called geographicLib, on sourceforge
9- or do the whole geographicLib, which looks like it also has gravity and likely GD-GC,
10-- and windows/linux, x86/x64 configs
11
12KARNEY UTM
13https://arxiv.org/pdf/1002.1417
14https://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM
15https://geographiclib.sourceforge.io
16Karneys nanometer utm Geo converters
17https://geographiclib.sourceforge.io/html/classGeographicLib_1_1TransverseMercator.html
18/KARNEY UTM
19TransverseMercator (real a, real f, real k0)
20void Forward (real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
21void Reverse (real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
22void Forward (real lon0, real lat, real lon, real &x, real &y) const
23void Reverse (real lon0, real x, real y, real &lat, real &lon) const
24
25*/
26
27#ifdef HAVE_GEOLIB
28
29#include <GeographicLib/TransverseMercator.hpp>
30#include <GeographicLib/DMS.hpp>
31#include <GeographicLib/Utility.hpp>
32#include <GeographicLib/Geocentric.hpp>
33using namespace GeographicLib;
34
35extern "C" {
36#include "fwgeolib.h"
37
38void * fgeo_initializeTM(double a, double f, double scaleFactor){
39 TransverseMercator * TMS = new TransverseMercator(a, f, scaleFactor);
40 return (void*)TMS;
41}
42void fgeo_tm2gd(void *fgeo,double easting, double northing, double dlon0, double *dlat, double *dlon){
43 double ddlat, ddlon;
44 TransverseMercator * TMS = (TransverseMercator *)fgeo;
45 TMS->Reverse(dlon0,easting,northing,ddlat,ddlon);
46 *dlat = ddlat;
47 *dlon = ddlon;
48}
49void fgeo_gd2tm(void *fgeo,double dlat, double dlon, double dlon0, double *easting, double *northing){
50 double dx, dy;
51 TransverseMercator * TMS = (TransverseMercator *)fgeo;
52 TMS->Forward(dlon0,dlat,dlon,dx,dy);
53 *easting = dx;
54 *northing = dy;
55}
56
57void * fgeo_initializeGC(double a, double f){
58 Geocentric * GC = new Geocentric(a, f);
59 return (void*)GC;
60}
61void fgeo_gc2gd(void *fgeo,double X, double Y, double Z, double *dlat, double *dlon, double *dh){
62 double ddlat, ddlon, ddh;
63 Geocentric * GC = (Geocentric *)fgeo;
64 GC->Reverse(X,Y,Z,ddlat,ddlon,ddh);
65 *dlat = ddlat;
66 *dlon = ddlon;
67 *dh = ddh;
68}
69void fgeo_gd2gc(void *fgeo, double dlat, double dlon, double dh, double *X, double *Y, double *Z){
70 double dx, dy, dz;
71 Geocentric * GC = (Geocentric *)fgeo;
72 GC->Forward(dlat, dlon, dh, dx,dy,dz);
73 *X = dx;
74 *Y = dy;
75 *Z = dz;
76}
77
78
79} //extern C
80
81#endif //HAVE_GEOLIB