示例#1
0
    //Maybe...http://answers.google.com/answers/threadview/id/782886.html
    //https://en.wikipedia.org/wiki/Position_of_the_Sun
    //https://en.wikipedia.org/wiki/Solar_azimuth_angle
    //http://www.itacanet.org/the-sun-as-a-source-of-energy/part-3-calculating-solar-angles/

    public double[] getZenithAndAzimuth(DateTime time, double longitude, double latitude, double timezone)
    {
        int daysInYear = 365;

        if (DateTime.IsLeapYear(time.Year))
        {
            daysInYear = 366;
        }


        //radians
        double fractionalYear = (2 * Math.PI / daysInYear) * (time.DayOfYear - 1 + ((time.Hour - 12) / 24));

        //eqptime in Minutes
        double eqtime = 229.18 * (0.000075 + 0.001868 * Math.Cos(fractionalYear) - 0.032077 * Math.Sin(fractionalYear) - 0.014615 * Math.Cos(2 * fractionalYear) - 0.040849 * Math.Sin(2 * fractionalYear));

        //decl in Radians
        double decl = 0.006918 - 0.399912 * Math.Cos(fractionalYear) + 0.070257 * Math.Sin(fractionalYear) - 0.006758 * Math.Cos(2 * fractionalYear) + 0.000907 * Math.Sin(2 * fractionalYear) - 0.002697 * Math.Cos(3 * fractionalYear) + 0.00148 * Math.Sin(3 * fractionalYear);

        double time_offset = eqtime + 4 * longitude - 60 * timezone;
        double tst         = time.Hour * 60 + time.Minute + time.Second / 60 + time_offset; //Tst= true solar time

        double ha = (tst / 4) - 180;                                                        //Solar Hour Angle in degrees

        //Debug.Log(ha);


        //Solar Zenith Angle, and solar azimuth angle in radians

        double sza = Math.Acos(MathD.Sin(latitude) * Math.Sin(decl) + MathD.Cos(latitude) * Math.Cos(decl) * MathD.Cos(ha));                  //Solar Zenith Angle in radians
        double saa = -(Math.Acos(-(MathD.Sin(latitude) * Math.Cos(sza) - Math.Sin(decl)) / (MathD.Cos(latitude) * Math.Sin(sza))) - Math.PI); //Solar Azimuth Angle

        //Wikiperdia solar azimuth angle
        //double saa = Math.Acos(
        //        (Math.Sin(decl) * Math.Cos(latitude) - Math.Cos(ha) * Math.Cos(decl) * Math.Sin(latitude)) / Math.Sin(sza)
        //    );

        double[] answer = new double[2];
        answer[0] = MathD.RadianToDegree(sza);
        answer[1] = MathD.RadianToDegree(saa);


        if (ha < 0 || ha > 180)
        {
            //answer[0] *= -1;
            answer[0] += 180;
        }

        Debug.LogFormat("Time: {0},\tZenith: {1},\tAzimuth: {2},\tHour Angle: {3}", time.ToString(), answer[0], answer[1], ha);

        return(answer);
    }