【问题标题】:Calculating time on the path of the sun计算太阳路径上的时间
【发布时间】:2018-02-17 17:40:29
【问题描述】:

作为java的初学者,我正在尝试一些简单的案例。从this SO post2nd link 到那里给出的pdf文件,我已经开发了这个代码:

import java.time.LocalTime;
import java.util.Calendar;
import static java.lang.Math.acos;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.tan;


/**
 * Created by rudra on 17/02/18.
 */

public class PathOfSun {

    static public double getTime() {
        LocalTime loacltime = LocalTime.now();//.getHour();
        int tzone = 5; //TODO: placeholder, will be calculated
        //    int localhour = time.getHour();
        int hour = loacltime.getHour();
        int min = loacltime.getMinute();
        int sec = loacltime.getSecond();
        double lat  =  latlang.Lat;
        double lang = latlang.Lang;
        Calendar calendar = Calendar.getInstance();
        int dayofyear = calendar.get(Calendar.DAY_OF_YEAR);
        int daysthisyear = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
        double pi = Math.PI;

        double gamma = (2 * pi / daysthisyear) * (dayofyear - 1 + (hour - 12) / 24);
        double eqtime = 229.18 * (0.000075 + 0.001868 * cos(gamma) - 0.032077 * sin(gamma) -
                0.014615 * cos(2 * gamma) - 0.04849 * sin(2 * gamma));
        double decl = 0.006918 - 0.399912 * cos(gamma) + 0.070257 * sin(gamma) - 0.006758 * cos(2 * gamma)
                + 0.000907 * sin(2 * gamma) - 0.002697 * cos(3 * gamma) + 0.00148 * sin(3 * gamma);
        double toffset = eqtime + 4 * lang + 60 * tzone;
        double tst = 60 * hour + min + sec / 60 + toffset;
        double ha = tst / 4 - 180;

        // Zenith
        double phi = acos(sin(lat) * sin(decl) + cos(lat) * cos(decl) * cos(ha));
        // Azimuth
        double theta = 180 - acos((sin(lat) * cos(phi) - sin(decl)) / (cos(lat) * sin(phi)));

        // Calculating the hourAngle as in second page
        // At sunrise
        double ha2 = acos(cos(90.8*180/pi)/cos(lat)*cos(decl)-tan(lat)*tan(decl));
        double stime = 720 - 4 * (lang - ha2) - eqtime;
        System.out.println("Time of Sun "+ stime);
        return stime;
    }

其中,当被称为:

    PathOfSun.getTime();

给出的时间错误,意味着日落和日出的时间 (+/- ha2) 给出的值几乎相同。

我的代码有错误吗? 请帮助我正确执行此操作。

【问题讨论】:

    标签: java datetime math


    【解决方案1】:

    我的建议,

    查看您在帖子中提供的NOAA 给定链接中的日出和日落特殊情况。

    由于太阳和地球大气的折射,日出和日落时间是特殊情况。因此,可能需要考虑这些特殊情况,以便返回的日出和日落时间是正确的。

    您可能要考虑的另一个特殊情况时间是中午时间。程序是否对此进行了计算,并且返回的时间与NOAA clock 给定的时间是否正确?该链接显示了不同时区的时间。

    作为包括我自己在内的大多数程序员都熟悉和挣扎的一句谚语和一句名言,“魔鬼在细节中”。在这种情况下是问题的特殊情况或边缘情况。

    如有任何问题和/或澄清,请发表评论,我们会尽力而为。

    【讨论】:

      猜你喜欢
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多