#include <iostream>
#include <cmath>
// Rakımı hesaplamalarda kullanmak için sabit bir değer olarak belirliyoruz
const double ELEVATION = 850.0; // metre cinsinden
// Dereceyi Radyana Çevir
double degToRad(double degree) {
return degree * M_PI / 180.0;
}
// Radyanı Dereceye Çevir
double radToDeg(double radian) {
return radian * 180.0 / M_PI;
}
// Bir değeri 0 ile 360 arasında tutar
double moreLess360(double value) {
while (value > 360 || value < 0) {
if (value > 360)
value -= 360;
else if (value < 0)
value += 360;
}
return value;
}
// Bir değeri 0 ile 24 arasında tutar
double moreLess24(double value) {
while (value > 24 || value < 0) {
if (value > 24)
value -= 24;
else if (value < 0)
value += 24;
}
return value;
}
// Ondalık saati Saat ve Dakikaya çevir
void doubleToHrMin(double number, int &hours, int &minutes) {
hours = std::floor(moreLess24(number));
minutes = std::floor(moreLess24(number - hours) * 60);
}
// Namaz vakitlerini hesaplar
void calcPrayerTimes(int year, int month, int day,
double longitude, double latitude, int timeZone,
double fajrTwilight, double ishaTwilight,
double &fajrTime, double &sunRiseTime, double &zuhrTime,
double &asrTime, double &maghribTime, double &ishaTime) {
double D = (367 * year) - ((year + static_cast<int>((month + 9) / 12)) * 7 / 4) + ((275 * month / 9) + day - 730531.5);
double L = moreLess360(280.461 + 0.9856474 * D);
double M = moreLess360(357.528 + 0.9856003 * D);
double Lambda = moreLess360(L + 1.915 * std::sin(degToRad(M)) + 0.02 * std::sin(degToRad(2 * M)));
double Obliquity = 23.439 - 0.0000004 * D;
double Alpha = radToDeg(std::atan(std::cos(degToRad(Obliquity)) * std::tan(degToRad(Lambda))));
Alpha = moreLess360(Alpha + 90 * (std::floor(Lambda / 90) - std::floor(Alpha / 90)));
double ST = 100.46 + 0.985647352 * D;
double Dec = radToDeg(std::asin(std::sin(degToRad(Obliquity)) * std::sin(degToRad(Lambda))));
double Durinal_Arc = radToDeg(std::acos((std::sin(degToRad(-0.8333 - 0.0347 * std::sqrt(ELEVATION))) - std::sin(degToRad(Dec)) * std::sin(degToRad(latitude))) /
(std::cos(degToRad(Dec)) * std::cos(degToRad(latitude)))));
double Noon = moreLess360(Alpha - ST);
double UT_Noon = Noon - longitude;
////////////////////////////////////////////
// Namaz Vakitlerinin Hesaplanması
//////////////////////////////////////////
// Temkin değerleri
double fajrTemkin = 0.0;
double sunriseTemkin = 0.0;
double zuhrTemkin = 0.0;
double asrTemkin = 0.0;
double maghribTemkin = 0.0;
double ishaTemkin = 0.0;
// Öğle vakti [yerel öğle]
zuhrTime = UT_Noon / 15.0 + timeZone + zuhrTemkin;
// İkindi vakti
double Asr_Alt = radToDeg(std::atan(1 + std::tan(degToRad(std::fabs(latitude - Dec)))));
double Asr_Arc = radToDeg(std::acos((std::sin(degToRad(90 - Asr_Alt)) - std::sin(degToRad(Dec)) * std::sin(degToRad(latitude))) /
(std::cos(degToRad(Dec)) * std::cos(degToRad(latitude))))) / 15.0;
asrTime = zuhrTime + Asr_Arc + asrTemkin;
// Sabah vakti
sunRiseTime = zuhrTime - Durinal_Arc / 15.0 + sunriseTemkin;
// Akşam vakti
maghribTime = zuhrTime + Durinal_Arc / 15.0 + maghribTemkin;
double Esha_Arc = radToDeg(std::acos((std::sin(degToRad(ishaTwilight)) - std::sin(degToRad(Dec)) * std::sin(degToRad(latitude))) /
(std::cos(degToRad(Dec)) * std::cos(degToRad(latitude))))) / 15.0;
ishaTime = zuhrTime + Esha_Arc + ishaTemkin;
double Fajr_Arc = radToDeg(std::acos((std::sin(degToRad(fajrTwilight)) - std::sin(degToRad(Dec)) * std::sin(degToRad(latitude))) /
(std::cos(degToRad(Dec)) * std::cos(degToRad(latitude))))) / 15.0;
fajrTime = zuhrTime - Fajr_Arc + fajrTemkin;
}
int main() {
double fajr, sunRise, zuhr, asr, maghrib, isha;
calcPrayerTimes(2024, 11, 12, 32.8497, 39.9114, 3, -19, -17, fajr, sunRise, zuhr, asr, maghrib, isha);
int hours, minutes;
doubleToHrMin(fajr, hours, minutes);
std::cout << "Fajr: " << hours << ":" << minutes << std::endl;
doubleToHrMin(sunRise, hours, minutes);
std::cout << "Sunrise: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
doubleToHrMin(zuhr, hours, minutes);
std::cout << "Zuhr: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
doubleToHrMin(asr, hours, minutes);
std::cout << "Asr: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
doubleToHrMin(maghrib, hours, minutes);
std::cout << "Maghrib: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
doubleToHrMin(isha, hours, minutes);
std::cout << "Isha: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
return 0;
}