| Jacob Sparre Andersen: Local coordinates from (longitude, latitude) | [ Computing | Science | LEGO | Comics ] |
|---|
When we create location-based games using a GPS receiver (of some kind), we need an efficient, not necessarily precise, formula for translating the geographic (longitude, latitude) coordinates into local Euklidian (x, y) coordinates.
[ This is not a big deal for a physicist, but I have been asked to write this note by a non-physicist colleague. ]
The original definition of the meter is that the distance from Equator to the North Pole through Paris is 107 m. We use this definition for our approximate translation from geographic to local coordinates:
90° latitude = 107 m
We assume that we have a local reference position, (longitudeO, latitudeO).
At a given latitude, the longitudinal circumference of a sphere is cos(latitude) times that at equator.
| x | = | cos(latitude) · (longitude - longitudeO) · 107m / 90° |
| y | = | (latitude - latitudeO) · 107m / 90° |
To make the games less predictable, we may want to make the orientation of the local coordinate system random. To do this, we randomly select an angle, a, between 0° and 360°. We call the local, rotated coordinates (i, j).
| i | = | x · cos(a) + y · sin(a) |
| j | = | y · cos(a) - x · sin(a) |
I have implemented the formulas above in Ada as the package
Coordinate_Transformations
:
You can learn about Ada in the
Ada
Programming
wikibook.
<jacob@jacob-sparre.dk>.