1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853:
|
using System;
namespace xWatchPhone { public class SunMoonEngine {
private struct coor { public double lon; public double lat;
public double ra; public double dec; public double raGeocentric; public double decGeocentric;
public double az; public double alt;
public double x; public double y; public double z;
public double radius; public double diameter; public double distance; public double distanceTopocentric; public double decTopocentric; public double raTopocentric;
public double anomalyMean; public double parallax; public double orbitLon;
public double moonAge; public double phase;
public string moonPhase; public string sign; }
private struct riseset { public double transit; public double rise; public double set;
public double cicilTwilightMorning; public double cicilTwilightEvening;
public double nauticalTwilightMorning; public double nauticalTwilightEvening;
public double astronomicalTwilightMorning; public double astronomicalTwilightEvening; }
public struct SunMoonRiseSet { public DateTime DayOfValues; public double twilightMorning; public double sunRise; public double sunCulmination; public double sunSet; public double twilightEvening;
public double moonRise; public double moonCulmination; public double moonSet; public double moonAge; public string moonPhase; }
private double pi = 0; private double DEG = 0; private double RAD = 0; private double lat; private double lon; private double seaLevel; private DateTime currDay;
public SunMoonEngine() { pi = Math.PI; DEG = pi / 180.0; RAD = 180.0 / pi;
lat = 52; lon = 13; seaLevel = 36; currDay = DateTime.Now; }
public SunMoonEngine(double latitude, double longitude, double meterAboveSeaLevel, DateTime interestingDay) { pi = Math.PI; DEG = pi/180.0; RAD = 180.0/pi;
lat = latitude; lon = longitude; seaLevel = meterAboveSeaLevel; currDay = interestingDay; }
public SunMoonRiseSet InitEngine(double latitude, double longitude, double meterAboveSeaLevel, DateTime interestingDay) { lat = latitude; lon = longitude; seaLevel = meterAboveSeaLevel; currDay = interestingDay;
return Compute(); }
private double sqr(double x) { return x * x; }
private int Int(double x) { return (x < 0) ? Convert.ToInt32(Math.Ceiling(x)) : Convert.ToInt32(Math.Floor(x)); }
private double frac(double x) { return (x - Math.Floor(x)); }
private double Mod(double a, double b) { return (a - Math.Floor(a / b) * b); }
private double Mod2Pi(double x) { return Mod(x, 2.0 * pi); }
private double round100000(double x) { return Math.Round(100000.0 * x) / 100000.0; } private double round10000(double x) { return Math.Round(10000.0 * x) / 10000.0; } private double round1000(double x) { return Math.Round(1000.0 * x) / 1000.0; } private double round100(double x) { return Math.Round(100.0 * x) / 100.0; } private double round10(double x) { return Math.Round(10.0 * x) / 10.0; }
private string HHMM(double hh) { if (hh == 0) return "";
var m = frac(hh) * 60.0; var h = Int(hh); if (m >= 59.5) { h++; m -= 60.0; } m = Math.Round(m);
var sH = "";
if (h < 10) sH = "0"; sH += h + ":";
if (m < 10) sH += "0"; sH += Convert.ToInt32(m);
return sH; }
private string Sign(double lon) { string[] signs = {"Widder", "Stier", "Zwillinge", "Krebs", "Löwe", "Jungfrau", "Waage", "Skorpion", "Schütze", "Steinbock", "Wassermann", "Fische"};
return (signs[Convert.ToInt16(Math.Floor(lon * RAD / 30))]); }
private double CalcJD(int day, int month, int year) { var jd = 2415020.5 - 64; if (month <= 2) { year--; month += 12; } jd += Int((year - 1900) * 365.25); jd += Int(30.6001 * (1 + month));
return jd + day; }
private double GMST(double JD) { var UT = frac(JD - 0.5) * 24.0; JD = Math.Floor(JD - 0.5) + 0.5; var T = (JD - 2451545.0) / 36525.0; var T0 = 6.697374558 + T * (2400.051336 + T * 0.000025862);
return Mod(T0 + UT * 1.002737909, 24.0); }
private double GMST2UT(double JD, double gmst) { JD = Math.Floor(JD - 0.5) + 0.5; var T = (JD - 2451545.0) / 36525.0; var T0 = Mod(6.697374558 + T * (2400.051336 + T * 0.000025862), 24.0); var UT = 0.9972695663 * ((gmst - T0));
return UT; }
private double GMST2LMST(double gmst, double lon) { var lmst = Mod(gmst + RAD * lon / 15, 24.0); return lmst; }
private coor Ecl2Equ(coor c0, double TDT) { var T = (TDT - 2451545.0) / 36525.0; var eps = (23.0 + (26 + 21.45 / 60.0) / 60.0 + T * (-46.815 + T * (-0.0006 + T * 0.00181)) / 3600.0) * DEG; var coseps = Math.Cos(eps); var sineps = Math.Sin(eps);
var sinlon = Math.Sin(c0.lon); coor c1 = c0; c1.ra = Mod2Pi(Math.Atan2((sinlon * coseps - Math.Tan(c0.lat) * sineps), Math.Cos(c0.lon))); c1.dec = Math.Asin(Math.Sin(c0.lat) * coseps + Math.Cos(c0.lat) * sineps * sinlon);
return c1; }
private coor Equ2Altaz(coor c0, double TDT, double geolat, double lmst) { var cosdec = Math.Cos(c0.dec); var sindec = Math.Sin(c0.dec); var lha = lmst - c0.ra; var coslha = Math.Cos(lha); var sinlha = Math.Sin(lha); var coslat = Math.Cos(geolat); var sinlat = Math.Sin(geolat);
var N = -cosdec * sinlha; var D = sindec * coslat - cosdec * coslha * sinlat; coor c1 = c0; c1.az = Mod2Pi(Math.Atan2(N, D)); c1.alt = Math.Asin(sindec * sinlat + cosdec * coslha * coslat);
return c1; }
private coor GeoEqu2TopoEqu(coor c0, coor observer, double lmst) { var cosdec = Math.Cos(c0.dec); var sindec = Math.Sin(c0.dec); var coslst = Math.Cos(lmst); var sinlst = Math.Sin(lmst); var coslat = Math.Cos(observer.lat); var sinlat = Math.Sin(observer.lat); var rho = observer.radius; var x = c0.distance * cosdec * Math.Cos(c0.ra) - rho * coslat * coslst; var y = c0.distance * cosdec * Math.Sin(c0.ra) - rho * coslat * sinlst; var z = c0.distance * sindec - rho * sinlat;
var c1 = c0; c1.distanceTopocentric = Math.Sqrt(x * x + y * y + z * z); c1.decTopocentric = Math.Asin(z / c1.distanceTopocentric); c1.raTopocentric = Mod2Pi(Math.Atan2(y, x));
return c1; }
private coor EquPolar2Cart(double lon, double lat, double distance) { coor c1 = new coor(); var rcd = Math.Cos(lat) * distance; c1.x = rcd * Math.Cos(lon); c1.y = rcd * Math.Sin(lon); c1.z = distance * Math.Sin(lat); return c1; }
private coor Observer2EquCart(double lon, double lat, double height, double gmst) { var flat = 298.257223563; var aearth = 6378.137; coor c1 = new coor(); var co = Math.Cos(lat); var si = Math.Sin(lat); var fl = 1.0 - 1.0 / flat; fl = fl * fl; si = si * si; var u = 1.0 / Math.Sqrt(co * co + fl * si); var a = aearth * u + height; var b = aearth * fl * u + height; var radius = Math.Sqrt(a * a * co * co + b * b * si); c1.y = Math.Acos(a * co / radius); c1.x = lon; if (lat < 0.0) { c1.y = -c1.y; } c1 = EquPolar2Cart(c1.x, c1.y, radius); var x = c1.x; var y = c1.y; var rotangle = gmst / 24 * 2 * pi; c1.x = x * Math.Cos(rotangle) - y * Math.Sin(rotangle); c1.y = x * Math.Sin(rotangle) + y * Math.Cos(rotangle); c1.radius = radius; c1.lon = lon; c1.lat = lat; return c1; }
private coor SunPosition(double TDT, double geolat, double lmst) { var D = TDT - 2447891.5;
var eg = 279.403303 * DEG; var wg = 282.768422 * DEG; var e = 0.016713; var a = 149598500; var diameter0 = 0.533128 * DEG; var MSun = 360 * DEG / 365.242191 * D + eg - wg; var nu = MSun + 360.0 * DEG / pi * e * Math.Sin(MSun);
var sunCoor = new coor(); sunCoor.lon = Mod2Pi(nu + wg); sunCoor.lat = 0; sunCoor.anomalyMean = MSun;
sunCoor.distance = (1 - sqr(e)) / (1 + e * Math.Cos(nu)); sunCoor.diameter = diameter0 / sunCoor.distance; sunCoor.distance *= a; sunCoor.parallax = 6378.137 / sunCoor.distance; var sunCoor1 = Ecl2Equ(sunCoor, TDT);
var sunCoor2 = Equ2Altaz(sunCoor1, TDT, geolat, lmst); sunCoor2.sign = Sign(sunCoor.lon);
return sunCoor2; }
private coor MoonPosition(coor sunCoor, double TDT, coor observer, double lmst) { var D = TDT - 2447891.5;
var l0 = 318.351648 * DEG; var P0 = 36.340410 * DEG; var N0 = 318.510107 * DEG; var i = 5.145396 * DEG; var e = 0.054900; var a = 384401; var diameter0 = 0.5181 * DEG; var parallax0 = 0.9507 * DEG; var l = 13.1763966 * DEG * D + l0; var MMoon = l - 0.1114041 * DEG * D - P0; var N = N0 - 0.0529539 * DEG * D; var C = l - sunCoor.lon; var Ev = 1.2739 * DEG * Math.Sin(2 * C - MMoon); var Ae = 0.1858 * DEG * Math.Sin(sunCoor.anomalyMean); var A3 = 0.37 * DEG * Math.Sin(sunCoor.anomalyMean); var MMoon2 = MMoon + Ev - Ae - A3; var Ec = 6.2886 * DEG * Math.Sin(MMoon2); var A4 = 0.214 * DEG * Math.Sin(2 * MMoon2); var l2 = l + Ev + Ec - Ae + A4; var V = 0.6583 * DEG * Math.Sin(2 * (l2 - sunCoor.lon)); var l3 = l2 + V; var N2 = N - 0.16 * DEG * Math.Sin(sunCoor.anomalyMean);
var moonCoor = new coor(); moonCoor.lon = Mod2Pi(N2 + Math.Atan2(Math.Sin(l3 - N2) * Math.Cos(i), Math.Cos(l3 - N2))); moonCoor.lat = Math.Asin(Math.Sin(l3 - N2) * Math.Sin(i)); moonCoor.orbitLon = l3;
moonCoor = Ecl2Equ(moonCoor, TDT); moonCoor.distance = (1 - sqr(e)) / (1 + e * Math.Cos(MMoon2 + Ec)); moonCoor.diameter = diameter0 / moonCoor.distance; moonCoor.parallax = parallax0 / moonCoor.distance; moonCoor.distance *= a; moonCoor = GeoEqu2TopoEqu(moonCoor, observer, lmst); moonCoor.raGeocentric = moonCoor.ra; moonCoor.decGeocentric = moonCoor.dec; moonCoor.ra = moonCoor.raTopocentric; moonCoor.dec = moonCoor.decTopocentric; moonCoor = Equ2Altaz(moonCoor, TDT, observer.lat, lmst); moonCoor.moonAge = Mod2Pi(l3 - sunCoor.lon); moonCoor.phase = 0.5 * (1 - Math.Cos(moonCoor.moonAge)); string[] phases = { "New moon", "Increasing crescent", "1st quarter", "Increasing Moon", "Full moon", "Decreasing Moon", "Last quarter", "decreasing crescent", "New moon" }; var mainPhase = 1.0 / 29.53 * 360 * DEG; var p = Mod(moonCoor.moonAge, 90.0 * DEG);
if (p < mainPhase || p > 90 * DEG - mainPhase) p = 2 * Math.Round(moonCoor.moonAge / (90.0 * DEG)); else p = 2 * Math.Floor(moonCoor.moonAge / (90.0 * DEG)) + 1;
moonCoor.moonPhase = phases[Convert.ToInt16(p)];
moonCoor.sign = Sign(moonCoor.lon);
return moonCoor; }
private double Refraction(double alt) { var pressure = 1015; var temperature = 10; var altdeg = alt * RAD;
if (altdeg < -2 || altdeg >= 90) return 0;
if (altdeg > 15) return 0.00452 * pressure / ((273 + temperature) * Math.Tan(alt));
var y = alt; var D = 0.0; var P = (pressure - 80.0) / 930.0; var Q = 0.0048 * (temperature - 10.0); var y0 = y; var D0 = D; var N = 0.0;
for (var i = 0; i < 3; i++) { N = y + (7.31 / (y + 4.4)); N = 1.0 / Math.Tan(N * DEG); D = N * P / (60.0 + Q * (N + 39.0)); N = y - y0; y0 = D - D0 - N; N = ((N != 0.0) && (y0 != 0.0)) ? y - N * (alt + D - y) / y0 : alt + D; y0 = y; D0 = D; y = N; } return D; }
private riseset GMSTRiseSet(coor c0, double lon, double lat, double h) { var tagbogen = Math.Acos((Math.Sin(h) - Math.Sin(lat) * Math.Sin(c0.dec)) / (Math.Cos(lat) * Math.Cos(c0.dec)));
riseset r1 = new SunMoonEngine.riseset(); r1.transit = RAD / 15 * (+c0.ra - lon); r1.rise = 24.0 + RAD / 15 * (-tagbogen + c0.ra - lon); r1.set = RAD / 15 * (+tagbogen + c0.ra - lon); r1.transit = Mod(r1.transit, 24); r1.rise = Mod(r1.rise, 24); r1.set = Mod(r1.set, 24);
return r1; }
private double InterpolateGMST(double gmst0, double gmst1, double gmst2, double timefactor) { return (timefactor * 24.07 * gmst1 - gmst0 * (gmst2 - gmst1)) / (timefactor * 24.07 + gmst1 - gmst2); }
private riseset RiseSet(double jd0UT, coor c1, coor c2, double lon, double lat, double timeinterval, double altitude) { var alt = 0.0; if (altitude == 0) alt = 0.5 * c1.diameter - c1.parallax + 34.0 / 60 * DEG;
var rise1 = GMSTRiseSet(c1, lon, lat, altitude); var rise2 = GMSTRiseSet(c2, lon, lat, altitude);
var rise = new riseset();
if (rise1.transit > rise2.transit && Math.Abs(rise1.transit - rise2.transit) > 18) rise2.transit += 24; if (rise1.rise > rise2.rise && Math.Abs(rise1.rise - rise2.rise) > 18) rise2.rise += 24; if (rise1.set > rise2.set && Math.Abs(rise1.set - rise2.set) > 18) rise2.set += 24; var T0 = GMST(jd0UT); var T02 = T0 - lon * RAD / 15 * 1.002738; if (T02 < 0) T02 += 24;
if (rise1.transit < T02) { rise1.transit += 24; rise2.transit += 24; } if (rise1.rise < T02) { rise1.rise += 24; rise2.rise += 24; } if (rise1.set < T02) { rise1.set += 24; rise2.set += 24; }
var decMean = 0.5 * (c1.dec + c2.dec); var psi = Math.Acos(Math.Sin(lat) / Math.Cos(decMean)); var y = Math.Asin(Math.Sin(alt) / Math.Sin(psi)); var dt = 240 * RAD * y / Math.Cos(decMean) / 3600; rise.transit = GMST2UT(jd0UT, InterpolateGMST(T0, rise1.transit, rise2.transit, timeinterval)); rise.rise = GMST2UT(jd0UT, InterpolateGMST(T0, rise1.rise, rise2.rise, timeinterval) - dt); rise.set = GMST2UT(jd0UT, InterpolateGMST(T0, rise1.set, rise2.set, timeinterval) + dt);
return rise; }
private riseset SunRise(double JD, double deltaT, double lon, double lat, double zone, bool recursive) { var jd0UT = Math.Floor(JD - 0.5) + 0.5; var coor1 = SunPosition(jd0UT + deltaT / 24.0 / 3600.0, 0, 0); var coor2 = SunPosition(jd0UT + 1.0 + deltaT / 24.0 / 3600.0, 0, 0); var risetemp = new riseset(); var rise = new riseset(); rise = RiseSet(jd0UT, coor1, coor2, lon, lat, 1, 0); if (!recursive) { if (zone > 0) { if (rise.rise >= 24 - zone || rise.transit >= 24 - zone || rise.set >= 24 - zone) { risetemp = SunRise(JD + 1, deltaT, lon, lat, zone, true); if (rise.rise >= 24 - zone) rise.rise = risetemp.rise; if (rise.transit >= 24 - zone) rise.transit = risetemp.transit; if (rise.set >= 24 - zone) rise.set = risetemp.set; } } else if (zone < 0) { if (rise.rise < -zone || rise.transit < -zone || rise.set < -zone) { risetemp = SunRise(JD - 1, deltaT, lon, lat, zone, true); if (rise.rise < -zone) rise.rise = risetemp.rise; if (rise.transit < -zone) rise.transit = risetemp.transit; if (rise.set < -zone) rise.set = risetemp.set; } }
rise.transit = Mod(rise.transit + zone, 24.0); rise.rise = Mod(rise.rise + zone, 24.0); rise.set = Mod(rise.set + zone, 24.0);
risetemp = RiseSet(jd0UT, coor1, coor2, lon, lat, 1, -6.0 * DEG); rise.cicilTwilightMorning = Mod(risetemp.rise + zone, 24.0); rise.cicilTwilightEvening = Mod(risetemp.set + zone, 24.0);
risetemp = RiseSet(jd0UT, coor1, coor2, lon, lat, 1, -12.0 * DEG); rise.nauticalTwilightMorning = Mod(risetemp.rise + zone, 24.0); rise.nauticalTwilightEvening = Mod(risetemp.set + zone, 24.0);
risetemp = RiseSet(jd0UT, coor1, coor2, lon, lat, 1, -18.0 * DEG); rise.astronomicalTwilightMorning = Mod(risetemp.rise + zone, 24.0); rise.astronomicalTwilightEvening = Mod(risetemp.set + zone, 24.0); } return rise; }
private riseset MoonRise(double JD, double deltaT, double lon, double lat, double zone, bool recursive) { var timeinterval = 0.5;
var jd0UT = Math.Floor(JD - 0.5) + 0.5; var suncoor1 = SunPosition(jd0UT + deltaT / 24.0 / 3600.0, 0, 0); var coor1 = MoonPosition(suncoor1, jd0UT + deltaT / 24.0 / 3600.0, new coor(), 0);
var suncoor2 = SunPosition(jd0UT + timeinterval + deltaT / 24.0 / 3600.0, 0, 0); var coor2 = MoonPosition(suncoor2, jd0UT + timeinterval + deltaT / 24.0 / 3600.0, new coor(), 0);
var risetemp = new riseset(); var rise = new riseset();
rise = RiseSet(jd0UT, coor1, coor2, lon, lat, timeinterval, 0);
if (!recursive) { if (zone > 0) { var riseprev = MoonRise(JD - 1.0, deltaT, lon, lat, zone, true);
if (rise.transit >= 24.0 - zone || rise.transit < -zone) { if (riseprev.transit < 24.0 - zone) rise.transit = 0.000000000; else rise.transit = riseprev.transit; }
if (rise.rise >= 24.0 - zone || rise.rise < -zone) { if (riseprev.rise < 24.0 - zone) rise.rise = 0.000000000; else rise.rise = riseprev.rise; }
if (rise.set >= 24.0 - zone || rise.set < -zone) { if (riseprev.set < 24.0 - zone) rise.set = 0.000000000; else rise.set = riseprev.set; }
} else if (zone < 0) { if (rise.rise < -zone || rise.set < -zone || rise.transit < -zone) { risetemp = MoonRise(JD + 1.0, deltaT, lon, lat, zone, true);
if (rise.rise < -zone) { if (risetemp.rise > -zone) rise.rise = 0.000000000; else rise.rise = risetemp.rise; }
if (rise.transit < -zone) { if (risetemp.transit > -zone) rise.transit = 0.000000000; else rise.transit = risetemp.transit; }
if (rise.set < -zone) { if (risetemp.set > -zone) rise.set = 0.000000000; else rise.set = risetemp.set; }
} }
if (rise.rise != 0.000000000) rise.rise = Mod(rise.rise + zone, 24.0); if (rise.transit != 0.000000000) rise.transit = Mod(rise.transit + zone, 24.0); if (rise.set != 0.000000000) rise.set = Mod(rise.set + zone, 24.0); } return rise; }
public double GetCurrLMST() { var JD0 = CalcJD(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year); var zone = (DateTime.Now - DateTime.UtcNow).Hours; var JD = JD0 + (DateTime.Now.Hour - zone + DateTime.Now.Minute / 60.0 + DateTime.Now.Second / 3600.0) / 24.0;
var longitude = lon * DEG; var gmst = GMST(JD); return GMST2LMST(gmst, longitude); }
public SunMoonRiseSet Compute() {
if (currDay.Year <= 1900 || currDay.Year >= 2100) throw new Exception("Diese Berechnung erlaubt nur eine Zeitperiode 1901-2099!");
var calculation = new SunMoonRiseSet();
calculation.DayOfValues = currDay;
var JD0 = CalcJD(currDay.Day, currDay.Month, currDay.Year); var zone = (DateTime.Now - DateTime.UtcNow).Hours; var JD = JD0 + (currDay.Hour - zone + currDay.Minute / 60.0 + currDay.Second / 3600.0) / 24.0; var DeltaT = 65.0; var TDT = JD + DeltaT / 24.0 / 3600.0;
var latitude = lat * DEG; var longitude = lon * DEG; var height = seaLevel * 0.001; var gmst = GMST(JD); var lmst = GMST2LMST(gmst, longitude);
var sunCoor = SunPosition(TDT, latitude, lmst * 15.0 * DEG); var sunRise = SunRise(JD0, DeltaT, longitude, latitude, zone, false);
calculation.sunCulmination = sunRise.transit; calculation.sunRise = sunRise.rise; calculation.sunSet = sunRise.set;
calculation.twilightMorning = sunRise.cicilTwilightMorning; calculation.twilightEvening = sunRise.cicilTwilightEvening;
var observerCart = Observer2EquCart(longitude, latitude, height, gmst); var moonCoor = MoonPosition(sunCoor, TDT, observerCart, lmst * 15.0 * DEG); var MoonLon = round1000(moonCoor.lon*RAD); var MoonLat = round1000(moonCoor.lat*RAD); var MoonRA = HHMM(moonCoor.ra*RAD/15.0); var MoonDec = round1000(moonCoor.dec*RAD); var MoonAz = round100(moonCoor.az*RAD); var MoonAlt = round10(moonCoor.alt*RAD+Refraction(moonCoor.alt)); calculation.moonAge = round1000(moonCoor.moonAge * RAD);
var MoonPhaseNumber = round1000(moonCoor.phase); calculation.moonPhase = moonCoor.moonPhase;
var MoonDistance = round10(moonCoor.distance); var MoonDiameter = round100(moonCoor.diameter*RAD*60.0); var moonRise = MoonRise(JD0, DeltaT, longitude, latitude, zone, false);
calculation.moonCulmination = moonRise.transit; calculation.moonRise = moonRise.rise; calculation.moonSet = moonRise.set;
return calculation; } } } |