Skip to content

Instantly share code, notes, and snippets.

@kikuchan
Created December 22, 2024 13:08
Show Gist options
  • Save kikuchan/3a0127b8eb19bcf49ad0a271d64b2ef0 to your computer and use it in GitHub Desktop.
Save kikuchan/3a0127b8eb19bcf49ad0a271d64b2ef0 to your computer and use it in GitHub Desktop.
maplibre-gl-js: light position calculation
function lightPosition(lat: number, lng: number) {
const sin = (d: number) => Math.sin(d * Math.PI / 180);
const cos = (d: number) => Math.cos(d * Math.PI / 180);
const acos = (v: number) => Math.acos(v) * 180 / Math.PI;
const b = acos(cos(lat) * cos(lng));
const a = acos(sin(lat) / sin(b));
return [-1, a, b] as [number, number, number];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment