fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. // Dereceyi Radyana Çevir
  5. double degToRad(double degree) {
  6. return degree * M_PI / 180.0;
  7. }
  8.  
  9. // Radyanı Dereceye Çevir
  10. double radToDeg(double radian) {
  11. return radian * 180.0 / M_PI;
  12. }
  13.  
  14. // Bir değeri 0 ile 360 arasında tutar
  15. double moreLess360(double value) {
  16. return value - 360.0 * std::floor(value / 360.0);
  17. }
  18.  
  19. // Ondalık saati Saat ve Dakikaya çevir
  20. void doubleToHrMin(double number, int &hours, int &minutes) {
  21. hours = static_cast<int>(std::floor(number));
  22. minutes = static_cast<int>(std::floor((number - hours) * 60));
  23. }
  24.  
  25. // Julian Tarihini Hesaplar
  26. double julianDate(int year, int month, int day) {
  27. if (month <= 2) {
  28. year -= 1;
  29. month += 12;
  30. }
  31. double A = std::floor(year / 100.0);
  32. double B = 2 - A + std::floor(A / 4.0);
  33. return std::floor(365.25 * (year + 4716)) + std::floor(30.6001 * (month + 1)) + day + B - 1524.5;
  34. }
  35.  
  36. // Güneşin Konumunu Hesaplar
  37. void sunPosition(double jd, double &declination, double &eqTime) {
  38. double d = jd - 2451545.0;
  39. double g = moreLess360(357.529 + 0.98560028 * d);
  40. double q = moreLess360(280.459 + 0.98564736 * d);
  41. double L = moreLess360(q + 1.915 * std::sin(degToRad(g)) + 0.020 * std::sin(degToRad(2 * g)));
  42.  
  43. double e = 23.439 - 0.00000036 * d;
  44. declination = radToDeg(std::asin(std::sin(degToRad(e)) * std::sin(degToRad(L))));
  45. double ra = radToDeg(std::atan2(std::cos(degToRad(e)) * std::sin(degToRad(L)), std::cos(degToRad(L)))) / 15.0;
  46. ra = ra - std::floor(ra / 24.0) * 24.0;
  47. eqTime = q / 15.0 - ra;
  48. }
  49.  
  50. // İmsak Vaktini Hesaplar
  51. void calcImsakTime(int year, int month, int day,
  52. double longitude, double latitude, int timeZone,
  53. double twilightAngle, double &imsakTime) {
  54. double jd = julianDate(year, month, day);
  55. double declination, eqTime;
  56. sunPosition(jd, declination, eqTime);
  57.  
  58. double noon = 12.0 - eqTime - (longitude / 15.0);
  59. double hourAngle = radToDeg(std::acos((std::cos(degToRad(twilightAngle)) - std::sin(degToRad(declination)) * std::sin(degToRad(latitude))) /
  60. (std::cos(degToRad(declination)) * std::cos(degToRad(latitude))))) / 15.0;
  61. imsakTime = noon - hourAngle + timeZone;
  62. }
  63.  
  64. int main() {
  65. // Ankara'nın koordinatları
  66. double ankaraLat = 39.9334;
  67. double ankaraLon = 32.8597;
  68. int timeZone = 3; // GMT+3
  69.  
  70. // İmsak vakti için alacakaranlık açısı
  71. double twilightAngle = -18.0;
  72.  
  73. double imsak;
  74. calcImsakTime(2016, 12, 1, ankaraLon, ankaraLat, timeZone, twilightAngle, imsak);
  75.  
  76. int hours, minutes;
  77. doubleToHrMin(imsak, hours, minutes);
  78. std::cout << "Ankara için İmsak Vakti (01.12.2016): " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
  79.  
  80. return 0;
  81. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Ankara için İmsak Vakti (01.12.2016): -2147483648:0-2147483648