/// <summary> /// this will move date to the nearest conjunction /// whether it is in future or in the past /// </summary> /// <returns></returns> protected GPGregorianTime movePosition() { double position = 0; double diff; double seconds = 0.5 / 86400.0; double prevSeconds = -1; for (int i = 0; i < 10; i++) { position = calculatePosition() / 360; if (Math.Abs(pJulianDate - prevSeconds) < seconds) { break; } prevSeconds = pJulianDate; diff = position * 30; pJulianDate -= diff; pStartDate.addDayHours(diff); } GPGregorianTime nt = new GPGregorianTime(pStartDate.getLocation()); nt.setJulianGreenwichTime(new GPJulianTime(GPAstroEngine.ConvertDynamicToUniversal(pJulianDate), 0.0)); return(nt); }
public GPGregorianTime TimeByAddingHours(double dHours) { GPGregorianTime vc = new GPGregorianTime(this); vc.addDayHours(dHours / 24.0); return(vc); }
public GPGregorianTime movePosition(int dir) { double unitLength = getUnitAverageLength(); int unitCount = getUnitCount(); double lowerLimit = 0.5; double upperLimit = unitCount - 0.5; double position = 0; bool over = false; bool under = false; double nextTithi = getCurrentPosition() + dir; double diff; double seconds = 0.5 / 86400.0; double prevSeconds = -1; if (dir > 0) { over = (nextTithi > upperLimit); under = (currentPosition < lowerLimit); } else { over = (currentPosition > upperLimit); under = (nextTithi < lowerLimit); } for (int i = 0; i < 10; i++) { position = calculatePosition(); //seconds = Convert.ToInt32((pJulianDate - Math.Floor(pJulianDate)) * 86400); if (Math.Abs(pJulianDate - prevSeconds) < seconds) { break; } if (over && position < lowerLimit) { position += unitCount; } else if (under && position > upperLimit) { position -= unitCount; } prevSeconds = pJulianDate; diff = (nextTithi - position) * unitLength; pJulianDate += diff; pStartDate.addDayHours(diff); } currentPosition = Convert.ToInt32(nextTithi) % unitCount; GPGregorianTime nt = new GPGregorianTime(pStartDate.getLocation()); nt.setJulianGreenwichTime(new GPJulianTime(GPAstroEngine.ConvertDynamicToUniversal(pJulianDate), 0.0)); return(nt); }
public static GPGregorianTime CalcTithiEndEx(GPGregorianTime vcStart, int GYear, int nMasa, int nPaksa, int nTithi, GPLocationProvider earth, out GPGregorianTime endTithi) { int i, gy, nType; GPGregorianTime d = new GPGregorianTime(earth); GPGregorianTime dtemp = new GPGregorianTime(earth); GPAstroData day = new GPAstroData(); int tithi; int counter; GPGregorianTime start = new GPGregorianTime(earth), end = new GPGregorianTime(earth); // SUNDATA sun; // MOONDATA moon; double sunrise; start.setDayHours(-1.0); end.setDayHours(-1.0); start.Clear(); end.Clear(); /* d = GetFirstDayOfYear(earth, nGYear + 1486); * d.shour = 0.5; * d.TimeZone = earth.tzone; */ d.Copy(vcStart); i = 0; do { d.AddDays(13); day.calculateDayData(d, earth); day.nMasa = day.determineMasa(d, out gy); day.nGaurabdaYear = gy; i++; }while (((day.nPaksa != nPaksa) || (day.nMasa != nMasa)) && (i <= 30)); if (i >= 30) { d.Clear(); endTithi = d; return(d); } // we found masa and paksa // now we have to find tithi tithi = nTithi + nPaksa * 15; if (day.nTithi == tithi) { // loc1 // find tithi juncts in this day and according to that times, // look in previous or next day for end and start of this tithi nType = 1; } else { if (day.nTithi < tithi) { // do increment of date until nTithi == tithi // but if nTithi > tithi // then do decrement of date counter = 0; while (counter < 30) { d.NextDay(); day.calculateDayData(d, earth); if (day.nTithi == tithi) { goto cont_2; } if ((day.nTithi < tithi) && (day.nPaksa != nPaksa)) { d.PreviousDay(); goto cont_2; } if (day.nTithi > tithi) { d.PreviousDay(); goto cont_2; } counter++; } // somewhere is error d.Clear(); nType = 0; } else { // do decrement of date until nTithi <= tithi counter = 0; while (counter < 30) { d.PreviousDay(); day.calculateDayData(d, earth); if (day.nTithi == tithi) { goto cont_2; } if ((day.nTithi > tithi) && (day.nPaksa != nPaksa)) { goto cont_2; } if (day.nTithi < tithi) { goto cont_2; } counter++; } // somewhere is error d.Clear(); nType = 0; } cont_2: if (day.nTithi == tithi) { // do the same as in loc1 nType = 1; } else { // nTithi != tithi and nTithi < tithi // but on next day is nTithi > tithi // that means we will find start and the end of tithi // in this very day or on next day before sunrise nType = 2; } } // now we know the type of day-accurancy // nType = 0 means, that we dont found a day // nType = 1 means, we find day, when tithi was present at sunrise // nType = 2 means, we found day, when tithi started after sunrise // but ended before next sunrise // sunrise = day.sun.getSunriseDayHours() / 360 + day.sun.rise.getLocation().getTimeZoneOffsetHours() / 24; if (nType == 1) { GPGregorianTime d1, d2; d.setDayHours(sunrise); GetPrevTithiStart(d, out d1); //d = d1; //d.shour += 0.02; GetNextTithiStart(d, out d2); endTithi = d2; return(d1); } else if (nType == 2) { GPGregorianTime d1, d2; d.setDayHours(sunrise); GetNextTithiStart(d, out d1); d.Copy(d1); d.addDayHours(0.1); GetNextTithiStart(d, out d2); endTithi = d2; return(d1); } // if nType == 0, then this algoritmus has some failure if (nType == 0) { d.Clear(); d.setDayHours(0.0); endTithi = d; } else { d.Copy(start); endTithi = end; } return(d); }