From 7a3e04a9b1c27b423cb66324654eacec65a1c752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Mon, 2 Oct 2023 00:35:36 +0300 Subject: [PATCH] fix: fixes node position calculation for earth graph Co-authored-by: Rassl --- src/transformers/earthGraph.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/transformers/earthGraph.ts b/src/transformers/earthGraph.ts index 51c206360..f5446baa4 100644 --- a/src/transformers/earthGraph.ts +++ b/src/transformers/earthGraph.ts @@ -23,13 +23,12 @@ export const getPointAbove = (point: Vector3, radius: number) => { } export const getPositionFromLngLat = (lng: number, lat: number, radius: number) => { - const latRad = (lat * Math.PI) / 180 - const lonRad = (lng * Math.PI) / 180 + const phi = (lat * Math.PI) / 180 + const theta = ((lng - 180) * Math.PI) / 180 - // Calculate the Cartesian coordinates - const x = radius * Math.cos(latRad) * Math.cos(lonRad) - const y = radius * Math.sin(latRad) - const z = radius * Math.cos(latRad) * Math.sin(lonRad) + const x = -radius * Math.cos(phi) * Math.cos(theta) + const y = radius * Math.sin(phi) + const z = radius * Math.cos(phi) * Math.sin(theta) return new Vector3(x, y, z) }