I have WGS84 points and I should convert to local coordinates (x, y, z) and plot in ThreeJs. I referred the below article and created a converted (refer code below)

Article: Calculate distance, bearing and more between Latitude/Longitude points :

Code: WGS84 to Local Coordinate Converter

function convertPoint(gpsPoint: GpsPoint, originPoint: GpsPoint): LocalPoint {
    // calculate distance between reference point and calibration Gps points
    const distanceInMeters = HaversineDistance.calculate(originPoint, gpsPoint);
    const bearingAngle = calculateBearing(originPoint, gpsPoint);
    const distance = distanceInMeters;
    const y = -(distance * Math.cos(bearingAngle));
    const x = distance * Math.sin(bearingAngle);
    const z = calculateZ(gpsPoint);
    return { x: x, y: y, z: z };

The result is not coming as expected.

The WGS84 is coming near to strait line. Find the screenshot below

WGS84 Output

But the converted local coordinates are not not strait line. it get curved.

Local Coordinate - Top view

Local Coordinate - Side view

In the code, the converted values having a big different. both x and y.

enter image description here

Help me to figure out where it is going wrong.

  • The article linked is about finding distances (among others) between lat/long values. Those formulas are not for converting to a local coordinate system.
    – Mintx
    Commented Jul 11, 2023 at 19:39
  • @Mintx, Can you help me with the conversion? I should convert to Local coordinate and plot it in ThreeJS canvas. Commented Jul 12, 2023 at 4:37

2 Answers 2


I figure it out the problems. There were two issues.

  1. Math functions will take value in radians. But I passes it as degree.

enter image description here

  1. While calculating the bearing, the angle was not converted back degree and normalized.

enter image description here

The code is updated in the main post as well as find the code here.


You could convert WGS84 to ECEF coordinates, then choose a ref point (should get a matrix 4x4) to convert to ENU coordinates.

But WGS84->ECEF is costly, you may directly use mapbox/cheap-ruler to convert WGS84 to ENU (kind of).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.