Hacker News new | ask | show | jobs
by pezezin 86 days ago
It depends on your use case. Storing WGS84 coordinates as 32-bit floats can incur on errors of several meters. It might be good for your fitness tracking application, but not for serious GIS usage.

Case in point: many years ago I was working on some software to generate 3D models from drone pictures. The first step of the pipeline was to convert from WGS84 to ECEF (https://en.wikipedia.org/wiki/Earth-centered,_Earth-fixed_co...), an absolute Cartesian coordinate system. Well, it turns out that at the scales involved, 6.371 million meters, 32-bit floats have a precision of half a meter, so the resulting models were totally broken.

Moving to 64-bit floats fixed this issue.

1 comments

Isn't that more of using a float to represent the number? Would be akin to trying to represent .5. Which, if your goal is to represent decimals, you are best off not using floats.

Granted, just storing it as a 32 bit integer is probably difficult for most uses. BCD just isn't common for most programmers. (Or fixed point, in general.)

If your goal is just to store the coordinates in a database, sure, use fixed point or whatever.

But any kind of calculation will involve a great deal of trigonometry, square roots, and the like. It is just easier to use floating point. Examples:

https://en.wikipedia.org/wiki/Geographic_coordinate_conversi...

https://en.wikipedia.org/wiki/Vincenty%27s_formulae

https://gist.github.com/govert/1b373696c9a27ff4c72a

You should be able to do the calculations in fixed point, easily enough? Indeed, it used to be that most embedded systems would use fixed point due to lack of float hardware.

I would actually think fixed point would be beneficial for its accuracy being a bit more controlled than floating point is. Yes, you lose the range of floating point. But I just don't see how that is relevant for numbers that are constrained to +/- 180 by definition.

That all said, I cannot and do not argue against that it is faster to get going with basic float/doubles, due to how commonly those are supported in base libraries.