【问题标题】:Daylight Hours Calculation日光时间计算
【发布时间】:2012-06-21 03:33:42
【问题描述】:

我在获取此表达式的数值时遇到问题,我尝试使用此公式计算白天时间。当我评估时,它最终给出了一个 NaN 这个表达式。

J 代表儒略日。 (例如今天 J = 172;)

任何帮助都将非常有价值, 谢谢

P = Math.asin(0.39795*Math.cos(0.2163108 + 2*Math.atan(0.9671396*Math.tan[0.00860*(J-186)])));

【问题讨论】:

  • 在这些情况下,当我遇到问题时,我总是将代码分成多行,以避免像你的情况那样混淆。试试看,你会看到“错误”是从哪里来的。
  • @NunoGonçalves..我做到了,它来自这部分“*Math.tan[0.00860*(J-186)]”
  • 也许 J 有问题...确保它返回一个好的值...
  • 我试过了......它说:无法使用 [] 将索引应用于 Math.tan[0.00860*(J-186)] 上的“方法组”类型的表达式......我删除 [ 到 ( 并且它起作用了...
  • @LolCat..谢谢老兄,现在可以使用了!干杯..我只是用括号替换了方括号,它起作用了。

标签: math trigonometry julian-date


【解决方案1】:

我试了一下,得到了答案……:

P = Math.Asin(0.39795 * Math.Cos(0.2163108 + 2 * Math.Atan(0.9671396 * Math.Tan(0.00860 * (J- 186)))));

我在 Math.tan[0.00860*(J-186)]))) 中将 "[" 更改为 "(" )

我得到了一个结果......(为了测试它,我将 J 更改为 172)

确保 P 是 Double

【讨论】:

    【解决方案2】:
        //GET LATITUDE
                latitude = document.getElementById("latit").value;
                L = latitude;
    
                //GET JULIAN DAY
                  Now=new Date();
                  Now_Y=Now.getYear();
                  if (Now_Y < 70)   { Now_Y=Now_Y*1+2000; }
                  if (Now_Y < 1900) { Now_Y=Now_Y*1+1900; }
                  Now_M=Now.getMonth();                     // Jan-Dec = 0-11
                  Now_D=Now.getDate();                      // 1-31
                  Now_H=Now.getHours();                     // 0-23
                  Now_N=Now.getMinutes();                   // 0-59
                  Now_S=Now.getSeconds();                   // 0-59
                  Now_U=Now.getMilliseconds();              // 0-999
                  Now_T=Now.getTime();                      // miliseconds since 1970-01-01
                  Now_O=Now.getTimezoneOffset();            // in minutes
                  Now_W=Now.getDay();                       // weekday: Sun-Sat = 0-6
                  Now_J=                                    // day of year (Julian day)
                    Math.round((                            // ...account for DST
                    (new Date(Now_Y,Now_M,Now_D))           // ...most recent midnight
                    - (new Date(Now_Y,0,0)))                // ...Dec. 31st midnight
                    /86400000);                             // ...mili-seconds per day
                  Gmt_N=Now_N+Now_O;
                  Gmt=new Date(Now_Y,Now_M,Now_D,Now_H,Gmt_N,Now_S);
                  Gmt_Y=Gmt.getYear();
                  if (Gmt_Y < 70)   { Gmt_Y=Gmt_Y*1+2000; }
                  if (Gmt_Y < 1900) { Gmt_Y=Gmt_Y*1+1900; }
                  Gmt_M=Gmt.getMonth();                     // Jan-Dec = 0-11
                  Gmt_D=Gmt.getDate();                      // 1-31
                  Gmt_J=                                    // day of year (Julian day)
                    Math.round((                            // ...account for DST
                    (new Date(Gmt_Y,Gmt_M,Gmt_D))           // ...most recent midnight
                    - (new Date(Gmt_Y,0,0)))                // ...Dec. 31st midnight
                    /86400000);                             // ...mili-seconds per day
                    alert("Julian Day: "+Gmt_J);
    
                J = Gmt_J;
    
                P = Math.asin(0.39795*Math.cos(0.2163108 + 2*Math.atan(0.9671396*Math.tan(0.00860*(J-186)))));
    
                alert("P is : "+P)
    
                pi = 3.14159265;
    
                var D = 24 - (24/pi)*Math.acos((Math.sin(0.8333*pi/180) + Math.sin(L*pi/180)*Math.sin(P))/ (Math.cos(L*pi/18
    
    0)*Math.cos(P)));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 2014-03-04
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多