salat-first
Version:
Islamic prayer times calculation with special support for Moroccan methods and Maliki madhab
70 lines (69 loc) • 2.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAKKAH_COORDINATES = void 0;
exports.calculateQiblaDirection = calculateQiblaDirection;
exports.getQiblaDirectionDescription = getQiblaDirectionDescription;
const coordinates_1 = require("../core/coordinates");
const math_1 = require("../core/math");
/**
* Coordinates of the Kaaba in Makkah
*/
exports.MAKKAH_COORDINATES = new coordinates_1.Coordinates(21.4225241, 39.8261818);
/**
* Calculates the Qibla direction from a given location
* @param coordinates The coordinates of the location
* @returns The direction in degrees from North clockwise
*/
function calculateQiblaDirection(coordinates) {
// Equation from "Spherical Trigonometry For the use of colleges and schools" page 50
const term1 = Math.sin((0, math_1.degreesToRadians)(exports.MAKKAH_COORDINATES.longitude) -
(0, math_1.degreesToRadians)(coordinates.longitude));
const term2 = Math.cos((0, math_1.degreesToRadians)(coordinates.latitude)) *
Math.tan((0, math_1.degreesToRadians)(exports.MAKKAH_COORDINATES.latitude));
const term3 = Math.sin((0, math_1.degreesToRadians)(coordinates.latitude)) *
Math.cos((0, math_1.degreesToRadians)(exports.MAKKAH_COORDINATES.longitude) -
(0, math_1.degreesToRadians)(coordinates.longitude));
const angle = Math.atan2(term1, term2 - term3);
return (0, math_1.unwindAngle)((0, math_1.radiansToDegrees)(angle));
}
/**
* Gets a human-readable description of the Qibla direction
* @param degrees The direction in degrees from North clockwise
* @returns A description of the direction
*/
function getQiblaDirectionDescription(degrees) {
// General compass directions
if (degrees >= 348.75 || degrees < 11.25)
return "North";
if (degrees >= 11.25 && degrees < 33.75)
return "North-Northeast";
if (degrees >= 33.75 && degrees < 56.25)
return "Northeast";
if (degrees >= 56.25 && degrees < 78.75)
return "East-Northeast";
if (degrees >= 78.75 && degrees < 101.25)
return "East";
if (degrees >= 101.25 && degrees < 123.75)
return "East-Southeast";
if (degrees >= 123.75 && degrees < 146.25)
return "Southeast";
if (degrees >= 146.25 && degrees < 168.75)
return "South-Southeast";
if (degrees >= 168.75 && degrees < 191.25)
return "South";
if (degrees >= 191.25 && degrees < 213.75)
return "South-Southwest";
if (degrees >= 213.75 && degrees < 236.25)
return "Southwest";
if (degrees >= 236.25 && degrees < 258.75)
return "West-Southwest";
if (degrees >= 258.75 && degrees < 281.25)
return "West";
if (degrees >= 281.25 && degrees < 303.75)
return "West-Northwest";
if (degrees >= 303.75 && degrees < 326.25)
return "Northwest";
if (degrees >= 326.25 && degrees < 348.75)
return "North-Northwest";
return "Unknown";
}