Skip to content

Instantly share code, notes, and snippets.

@miketahani
Created April 22, 2020 00:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketahani/f790ee8bb3142511722aa03561925456 to your computer and use it in GitHub Desktop.
Save miketahani/f790ee8bb3142511722aa03561925456 to your computer and use it in GitHub Desktop.
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