forked from batoulapps/adhan-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQibla.ts
24 lines (21 loc) · 849 Bytes
/
Qibla.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Coordinates from './Coordinates';
import { degreesToRadians, radiansToDegrees, unwindAngle } from './MathUtils';
export default function qibla(coordinates: Coordinates) {
const makkah = new Coordinates(21.4225241, 39.8261818);
// Equation from "Spherical Trigonometry For the use of colleges and schools" page 50
const term1 = Math.sin(
degreesToRadians(makkah.longitude) -
degreesToRadians(coordinates.longitude),
);
const term2 =
Math.cos(degreesToRadians(coordinates.latitude)) *
Math.tan(degreesToRadians(makkah.latitude));
const term3 =
Math.sin(degreesToRadians(coordinates.latitude)) *
Math.cos(
degreesToRadians(makkah.longitude) -
degreesToRadians(coordinates.longitude),
);
const angle = Math.atan2(term1, term2 - term3);
return unwindAngle(radiansToDegrees(angle));
}