Spaces:
Paused
Paused
Download lib/mathHelpers.js from Adhyasta/gcs-backend-server: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/Adhyasta/gcs-backend-server/resolve/main/lib/mathHelpers.js
- Command line
-
hf download hf://spaces/Adhyasta/gcs-backend-server/lib/mathHelpers.js
-
curl -L -o mathHelpers.js https://huggingface.co/spaces/Adhyasta/gcs-backend-server/resolve/main/lib/mathHelpers.js
1.61 kB
| // Credits to https://stackoverflow.com/a/48764436/6156700 | |
| const isRound = (num, decimalPlaces) => { | |
| const p = Math.pow(10, decimalPlaces) | |
| return Math.round(num * p) / p === num | |
| } | |
| const round = (num, decimalPlaces) => { | |
| if (isRound(num, decimalPlaces || 0)) { | |
| return num | |
| } | |
| const p = Math.pow(10, decimalPlaces || 0) | |
| const n = (num * p) * (1 + Number.EPSILON) | |
| return Math.round(n) / p | |
| } | |
| const toDegree = (rad) => { | |
| const pi = 3.141592653589793 | |
| return rad * (180 / pi) | |
| } | |
| // Added from Adhyasta-GCS-Webview/src/helper/mathHelper.js | |
| const calculateDistance = (lat1, lon1, alt1, lat2, lon2, alt2) => { | |
| const R = 6371 // Radius of the Earth in kilometers | |
| const lat1Rad = (lat1 * Math.PI) / 180 | |
| const lon1Rad = (lon1 * Math.PI) / 180 | |
| const lat2Rad = (lat2 * Math.PI) / 180 | |
| const lon2Rad = (lon2 * Math.PI) / 180 | |
| const dLat = lat2Rad - lat1Rad | |
| const dLon = lon2Rad - lon1Rad | |
| // const dAlt = alt2 - alt1 // Altitude difference | |
| const a = | |
| Math.sin(dLat / 2) * Math.sin(dLat / 2) + | |
| Math.cos(lat1Rad) * | |
| Math.cos(lat2Rad) * | |
| Math.sin(dLon / 2) * | |
| Math.sin(dLon / 2) | |
| const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) | |
| const distanceInKilometers = R * c | |
| const distanceInMeters = distanceInKilometers * 1000 | |
| // Calculate the 3D distance, considering altitude | |
| // const altitudeDifference = Math.abs(alt2 - alt1); | |
| // const altitudeCorrection = Math.sqrt( | |
| // Math.pow(distanceInMeters, 2) + Math.pow(altitudeDifference, 2) | |
| // ); | |
| return distanceInMeters | |
| } | |
| module.exports = { | |
| round, | |
| toDegree, | |
| calculateDistance | |
| } | |