Skip to content

Instantly share code, notes, and snippets.

@salmanyaqoob
Created March 29, 2021 07:48
Show Gist options
  • Select an option

  • Save salmanyaqoob/3305d8f5e7c9f5a83cf110d52abe68ae to your computer and use it in GitHub Desktop.

Select an option

Save salmanyaqoob/3305d8f5e7c9f5a83cf110d52abe68ae to your computer and use it in GitHub Desktop.
qibla(coordinates) {
const makkah = {
latitude: 21.42252,
longitude: 39.82621
};
const term1 = Math.sin(this.degreesToRadians(makkah.longitude) - this.degreesToRadians(coordinates.longitude));
const term2 = Math.cos(this.degreesToRadians(coordinates.latitude)) * Math.tan(this.degreesToRadians(makkah.latitude));
const term3 = Math.sin(this.degreesToRadians(coordinates.latitude)) * Math.cos(this.degreesToRadians(makkah.longitude) - this.degreesToRadians(coordinates.longitude));
const angle = Math.atan2(term1, term2 - term3);
return this.unwindAngle(this.radiansToDegrees(angle));
},
degreesToRadians(degrees) {
return degrees * Math.PI / 180.0;
},
radiansToDegrees(radians) {
return radians * 180.0 / Math.PI;
},
normalizeToScale(number, max) {
return number - max * Math.floor(number / max);
},
unwindAngle(angle) {
return this.normalizeToScale(angle, 360.0);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment