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)

Implemented in Ada

I have implemented the formulas above in Ada as the package Coordinate_Transformations:

Package specification:
coordinate_transformations.ads
Package body:
coordinate_transformations.adb
Text I/O package:
coordinate_transformations-angle_in_degrees_text_io.ads
From degrees-decimal minutes function specification:
coordinate_transformations-from_degrees_minutes_decimal_minutes.ads
From degrees-decimal minutes function body:
coordinate_transformations-from_degrees_minutes_decimal_minutes.adb
Demonstration procedure:
test_coordinate_transformations.adb

You can learn about Ada in the Ada Programming wikibook.


Curriculum vitaePublication listProductsScienceRSS feeds

JSA Research & Innovation • Jægerparken 5, 2. th. • 2970 Hørsholm • Danmark

jacob@jacob-sparre.dkwww.jacob-sparre.dk