On Monday 26 April 2010 11:20:38 Brian Schack wrote:
> The function geo_inverse_wgs_84 either produces a segmentation fault or
> goes into an infinite loop in some situations. I've attached a short
> program that illustrates some of the problems. I can't suggest any
> fixes, as the math is beyond me, so I'm hoping someone on this list can
> take a look at it and figure out what's wrong.
geo_inverse_wgs_84() is a macro that winds up calling _geo_inverse_wgs_84()
in simgear/math/SGGeodesy.cxx.
Between lines 336 and 368 the code is trying to trap all the "special" cases,
and recursively calls itself with cooked values. Somewhere in this bit of
code I think we're missing some cases or taking the wrong actions.
I parameterized Brian's code so I could really beat on it...
jent...@debian:~/src/scratch$ ./geod 0. 0. 0. 179.39
90.00, 270.00, 19970 km
jent...@debian:~/src/scratch$ ./geod 0. 0. 0. 179.399
0.00, 0.00, -0 km
jent...@debian:~/src/scratch$ ./geod 0. 0. 0. 180.
Segmentation fault
jent...@debian:~/src/scratch$ ./geod 0.1 0.1 0.1 179.45
46.71, 313.29, 19954 km
jent...@debian:~/src/scratch$ ./geod 0.1 0.1 0.1 179.455
46.37, 313.63, 19954 km
jent...@debian:~/src/scratch$ ./geod 0.1 0.1 0.1 179.459
^C (hung)
jent...@debian:~/src/scratch$ ./geod 0.1 0.1 0.1 180.
0.00, 0.00, -0 km
Not only are we segfaulting and hanging, but sometimes we're wrong, too.
Thanks,
Ron
//g++ geod.c -o geod -lsgmath -lsgstructure
#include <stdio.h>
#include <simgear/math/sg_geodesy.hxx>
int main(int argc, char *argv[])
{
double az1, az2, s;
double lat1, lat2, lon1, lon2;
int i, j;
if (argc != 5) return(0);
lat1 = atof(argv[1]);
lon1 = atof(argv[2]);
lat2 = atof(argv[3]);
lon2 = atof(argv[4]);
// return !SGGeodesy::inverse(SGGeod::fromDeg(lon1, lat1),
// SGGeod::fromDeg(lon2, lat2), *az1, *az2, *s);
geo_inverse_wgs_84(lat1, lon1, lat2, lon2, &az1, &az2, &s);
printf("%0.2f, %0.2f, %0.0f km\n", az1, az2, s/1000);
}
------------------------------------------------------------------------------
_______________________________________________
Flightgear-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/flightgear-devel