Skip to content

Commit

Permalink
remove absolute value calculations
Browse files Browse the repository at this point in the history
this gave bad averageScales when the point and origin where on different sides of the equator.
  • Loading branch information
hambsch committed Apr 22, 2024
1 parent 4b1ba56 commit 291cfa3
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/api/coords-to-vector-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ export function coordsToVector3(point: Coords, origin: Coords): Vector3Tuple {
// dynamic step size based on latitude difference. calculate the mercator unit scale at origin
// and the scale average along the line to the point for better accuracy far from origin
const steps = Math.ceil(Math.abs(point.latitude - origin.latitude)) * 100 + 1;
const absOriginLat = Math.abs(origin.latitude); // use abs values for scale calculation (same scale for north and south)
const absPointLat = Math.abs(point.latitude);
const avgScale = averageMercatorScale(absOriginLat, absPointLat, steps);

const z = (zOld / getMercatorScale(absOriginLat)) * avgScale;
const avgScale = averageMercatorScale(origin.latitude, point.latitude, steps);

const z = (zOld / getMercatorScale(origin.latitude)) * avgScale;
return [x, y, z] as Vector3Tuple;
}

0 comments on commit 291cfa3

Please sign in to comment.