# Conversion between geographic and FS XY coordinates

Often it is needed to convert between geographic (latitude and longitude) coordinates and the XY coordinates relative to a reference point. Many 3D modelling programs for example use such coordinates. With the formulas given below it is possible to convert between those two systems.

These formulas do not apply to FSX. FSX uses a curved earth and therefore geocentric coordinates need to be used. The difference between geocentric coordinates and the XY coordinates described here will increase with increasing distance from the reference point. But at 500 meter distance the error is almost 1 meter already.

## Geographic to XY

This formula gives the XY coordinates from a given reference point for a set of geographic coordinates.

``` x = (lon - lon_ref) * (40075000.0 / (2.0 * PI)) * Cos(lat_ref)
y = (lat - lat_ref) * (40007000.0 / (2.0 * PI))
```

Where (lat_ref, lon_ref) is the reference point and (lat, lon) is the geographic location of which you want to know the XY coordinates.

Be aware that the formula assumes all geographic coordinates are given in radians.

## XY to Geographic

This formula gives the geographic coordinates for a XY offset from the reference point.

``` lat = lat_ref + y / (40007000.0 / (2.0 * PI))
lon = lon_ref + x / ((40075000.0 / (2.0 * PI)) * Cos(lat_ref))
```

Where (lat_ref, lon_ref) is the reference point and (x,y) the XY offset from this reference point of which you want to know the geographic coordinates.

Be aware that the formula assumes all geographic coordinates are given in radians.