# Convert WGS84 to Local Point

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)

``````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 But the converted local coordinates are not not strait line. it get curved.  In the code, the converted values having a big different. both x and y. 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. Jul 11 at 19:39
• @Mintx, Can you help me with the conversion? I should convert to Local coordinate and plot it in ThreeJS canvas. Jul 12 at 4:37

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

1. Math functions will take value in radians. But I passes it as degree. 1. While calculating the bearing, the angle was not converted back degree and normalized. 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).