| 56 | * Create a coordinate transform for a given origin. |
| 57 | */ |
| 58 | export function createTransform(origin: GpsCoord): CoordinateTransform { |
| 59 | const latRad = (origin.lat * Math.PI) / 180; |
| 60 | |
| 61 | // Radius of curvature in the meridian |
| 62 | const Rm = |
| 63 | (WGS84_A * (1 - WGS84_E2)) / Math.pow(1 - WGS84_E2 * Math.sin(latRad) ** 2, 1.5); |
| 64 | |
| 65 | // Radius of curvature in the prime vertical |
| 66 | const Rn = WGS84_A / Math.sqrt(1 - WGS84_E2 * Math.sin(latRad) ** 2); |
| 67 | |
| 68 | // Meters per degree |
| 69 | const metersPerDegLat = (Math.PI / 180) * Rm; |
| 70 | const metersPerDegLon = (Math.PI / 180) * Rn * Math.cos(latRad); |
| 71 | |
| 72 | return { |
| 73 | origin, |
| 74 | metersPerDegLat, |
| 75 | metersPerDegLon, |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Convert GPS coordinate to local ENU meters relative to transform origin. |