# Jacob Sparre Andersen

## Local coordinates from (longitude, latitude)

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. ]

Longitude
East-West, positive East of Greenwich, negative West of Greenwich, going from -180░ to +180░.
Latitude
North-South, positive North of Equator, negative South of Equator, going from -90░ to +90░.

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░

## Random rotation of the local coordinates

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:

Package specification:
Package body: