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. 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