#include <iostream>
#include <cmath>
// 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) {
return value - 360.0 * std::floor(value / 360.0);
}
// Ondalık saati Saat ve Dakikaya çevir
void doubleToHrMin(double number, int &hours, int &minutes) {
hours = static_cast<int>(std::floor(number));
minutes = static_cast<int>(std::floor((number - hours) * 60));
}
// Julian Tarihini Hesaplar
double julianDate(int year, int month, int day) {
if (month <= 2) {
year -= 1;
month += 12;
}
double A = std::floor(year / 100.0);
double B = 2 - A + std::floor(A / 4.0);
return std::floor(365.25 * (year + 4716)) + std::floor(30.6001 * (month + 1)) + day + B - 1524.5;
}
// Güneşin Konumunu Hesaplar
void sunPosition(double jd, double &declination, double &eqTime) {
double d = jd - 2451545.0;
double g = moreLess360(357.529 + 0.98560028 * d);
double q = moreLess360(280.459 + 0.98564736 * d);
double L = moreLess360(q + 1.915 * std::sin(degToRad(g)) + 0.020 * std::sin(degToRad(2 * g)));
double e = 23.439 - 0.00000036 * d;
declination = radToDeg(std::asin(std::sin(degToRad(e)) * std::sin(degToRad(L))));
double ra = radToDeg(std::atan2(std::cos(degToRad(e)) * std::sin(degToRad(L)), std::cos(degToRad(L)))) / 15.0;
ra = ra - std::floor(ra / 24.0) * 24.0;
eqTime = q / 15.0 - ra;
}
// İmsak Vaktini Hesaplar
void calcImsakTime(int year, int month, int day,
double longitude, double latitude, int timeZone,
double twilightAngle, double &imsakTime) {
double jd = julianDate(year, month, day);
double declination, eqTime;
sunPosition(jd, declination, eqTime);
double noon = 12.0 - eqTime - (longitude / 15.0);
double hourAngle = radToDeg(std::acos((std::cos(degToRad(twilightAngle)) - std::sin(degToRad(declination)) * std::sin(degToRad(latitude))) /
(std::cos(degToRad(declination)) * std::cos(degToRad(latitude))))) / 15.0;
imsakTime = noon - hourAngle + timeZone;
}
int main() {
// Ankara'nın koordinatları
double ankaraLat = 39.9334;
double ankaraLon = 32.8597;
int timeZone = 3; // GMT+3
// İmsak vakti için alacakaranlık açısı
double twilightAngle = -18.0;
double imsak;
calcImsakTime(2016, 12, 1, ankaraLon, ankaraLat, timeZone, twilightAngle, imsak);
int hours, minutes;
doubleToHrMin(imsak, hours, minutes);
std::cout << "Ankara için İmsak Vakti (01.12.2016): " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
return 0;
}