Beispiel #1
0
        private static double Atan2(double y, double x)
        {
            double outValue = 0;

            if (x < 0)
            {
                outValue = MathEx.Atan(y / x) + MathEx.PI;
            }
            if ((x > 0) && (y >= 0))
            {
                outValue = MathEx.Atan(y / x);
            }
            if ((x > 0) && (y < 0))
            {
                outValue = MathEx.Atan(y / x) + 2 * MathEx.PI;
            }
            if ((x == 0) && (y > 0))
            {
                outValue = MathEx.PI / 2;
            }
            if ((x == 0) && (y < 0))
            {
                outValue = 3 * MathEx.PI / 2;
            }
            if ((x == 0) && (y == 0))
            {
                outValue = 0;
            }
            return(outValue);
        }
Beispiel #2
0
        private int Calculate(Direction direction)
        {
            // doy (N)
            int N = date.DayOfYear;

            // appr. time (t)
            double lngHour = longitude / 15.0;

            double t;

            if (direction == Direction.Sunrise)
            {
                t = N + ((6.0 - lngHour) / 24.0);
            }
            else
            {
                t = N + ((18.0 - lngHour) / 24.0);
            }

            // mean anomaly (M)
            double M = (0.9856 * t) - 3.289;

            // true longitude (L)
            double L = M + (1.916 * MathEx.Sin(Deg2Rad(M))) + (0.020 * MathEx.Sin(Deg2Rad(2 * M))) + 282.634;

            L = FixValue(L, 0, 360);

            // right asc (RA)
            double RA = Rad2Deg(MathEx.Atan(0.91764 * MathEx.Tan(Deg2Rad(L))));

            RA = FixValue(RA, 0, 360);

            // adjust quadrant of RA
            double Lquadrant  = (Math.Floor(L / 90.0)) * 90.0;
            double RAquadrant = (Math.Floor(RA / 90.0)) * 90.0;

            RA = RA + (Lquadrant - RAquadrant);

            RA = RA / 15.0;

            // sin cos DEC (sinDec / cosDec)
            double sinDec = 0.39782 * MathEx.Sin(Deg2Rad(L));
            double cosDec = MathEx.Cos(MathEx.Asin(sinDec));

            // local hour angle (cosH)
            double cosH = (MathEx.Cos(Deg2Rad((double)zenith / 1000.0f)) - (sinDec * MathEx.Sin(Deg2Rad(latitude)))) / (cosDec * MathEx.Cos(Deg2Rad(latitude)));

            // local hour (H)
            double H;

            if (direction == Direction.Sunrise)
            {
                H = 360.0 - Rad2Deg(MathEx.Acos(cosH));
            }
            else
            {
                H = Rad2Deg(MathEx.Acos(cosH));
            }

            H = H / 15.0;

            // time (T)
            double T = H + RA - (0.06571 * t) - 6.622;

            // universal time (T)
            double UT = T - lngHour;

            UT += utcOffset;  // local UTC offset

            if (daylightChanges != null)
            {
                if ((date > daylightChanges.Start) && (date < daylightChanges.End))
                {
                    UT += (double)daylightChanges.Delta.Ticks / 36000000000;
                }
            }

            UT = FixValue(UT, 0, 24);

            return((int)Math.Round(UT * 3600));  // Convert to seconds
        }