Created
April 22, 2020 00:35
-
-
Save miketahani/f790ee8bb3142511722aa03561925456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const radians = deg => deg * Math.PI / 180 | |
// @param {Number} z Offset from radius | |
export default function convertLatLngToSphere (lat, lng, baseRadius, z) { | |
// radians | |
const phi = radians(lat) | |
const theta = radians(lng - 180) | |
const radius = baseRadius + z | |
return [ | |
-radius * Math.cos(phi) * Math.cos(theta), // x | |
radius * Math.sin(phi), // y | |
radius * Math.cos(phi) * Math.sin(theta) // z | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment