Created
March 29, 2021 07:48
-
-
Save salmanyaqoob/3305d8f5e7c9f5a83cf110d52abe68ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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