Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 试着计算日出…ain';我没有得到正确的答案_Java - Fatal编程技术网

Java 试着计算日出…ain';我没有得到正确的答案

Java 试着计算日出…ain';我没有得到正确的答案,java,Java,这是我当前的代码: public class Sunpos { final private double Pi = Math.PI; final private double eul = 2.71828182845904523552 ; final private double sonauf = 90; final private double RAD = 0.017453292519943295769236907684886; public double su

这是我当前的代码:

    public class Sunpos {
   final private double Pi = Math.PI;
   final private double eul = 2.71828182845904523552 ;
   final private double sonauf = 90;
   final private double RAD = 0.017453292519943295769236907684886;

public double sunrisefinal (double Breitengrad, double Laengengrad, int tagzahl, int sommerzeit, int nacht) {

    double lngHour = Laengengrad/15;
    double t = tagzahl + ((6 - lngHour)/24);

    // double ab = tagzahl + ((18 - lngHour)/24);
    double M = (0.9856 * t) - 3.289;
    double L = M + (1.916 * Math.sin(M)) + (0.020 * Math.sin(2 * M)) + 282.634;

        if (L >= 359) { L -= 360; }
        else if (L < 0) { L += 360; }  

    double RA = (Math.atan(0.91764 * Math.tan(Pi/180)*L));

        if (RA >= 359) { RA -= 360; }
        else if (RA < 0) { RA += 360; }

    double Lquadrant = (Math.floor(L/90)*90);
    double RAquadrant = (Math.floor(RA/90))*90;
    RA = RA + (Lquadrant - RAquadrant);
    RA = RA/15;

    double sinDec = 0.39782 * Math.sin((Pi/180)*L);
    double cosDec = (180/Pi)*(Math.cos(Math.asin(sinDec)));
    double cosH = (Math.cos((Pi/180)*sonauf)-(sinDec*Math.sin((Pi/180)*Breitengrad)))/(cosDec * Math.cos((Pi/180)*Breitengrad));
    double H = 360 - Math.acos(cosH);
    H /= 15;

    double T = H + RA -(0.06571 * t) - 6.622;
    double UTC = T - lngHour;

        if (UTC >= 23) { UTC -= 24; }
        else if (UTC < 0) { UTC += 24; }

    double locTime = UTC; // Fuer die schweiz!
    System.out.println(locTime);
    return(0);


}
公共类Sunpos{
最终私有双Pi=Math.Pi;
最终私人双eul=2.71828182845904523552;
最终私人双人索纳夫=90;
最终私人双拉德=0.017453292519943295769236907684886;
公共双人决赛(双人布雷滕格勒、双人兰根格勒、内塔扎尔、内索默泽特、内纳赫特){
双lngHour=Laengrad/15;
双t=tagzahl+((6-lngHour)/24);
//双ab=tagzahl+((18-lngHour)/24);
双M=(0.9856*t)-3.289;
双L=M+(1.916*数学sin(M))+(0.020*数学sin(2*M))+282.634;
如果(L>=359){L-=360;}
如果(L<0){L+=360;}
双RA=(数学atan(0.91764*Math.tan(Pi/180)*L));
如果(RA>=359){RA-=360;}
如果(RA<0){RA+=360;}
双象限=(数学楼层(L/90)*90);
双象限=(数学楼层(RA/90))*90;
RA=RA+(1象限-RA象限);
RA=RA/15;
双sinDec=0.39782*数学sin((π/180)*L);
双cosDec=(180/Pi)*(Math.cos(Math.asin(sinDec));
双余弦=(数学余弦((Pi/180)*sonauf)-(sinDec*数学余弦((Pi/180)*Breitengrad))/(cosDec*数学余弦((Pi/180)*Breitengrad));
双H=360-数学acos(cosH);
H/=15;
双T=H+RA-(0.06571*T)-6.622;
双UTC=T-lngHour;
如果(UTC>=23){UTC-=24;}
如果(UTC<0){UTC+=24;}
double locTime=UTC;//Fuer die schweiz!
系统输出打印项次(locTime);
返回(0);
}
输入如下:(50,10294,1,0)。最后2个可以忽略

现在我基于以下页面:

根据网站,代码应该是完整的,但是我没有得到任何接近预期结果的地方。我今天应该得到7.5左右,但我得到了9.358

现在,这可能是因为有辐射度/度数的东西?我不太清楚,因为我一直在尝试将这些转换器(Pi/180)插入代码中,没有任何可用的结果


有人能告诉我应该把它们放在哪里或者给我指出正确的方向吗?我已经在这上面花了太多的时间,现在我已经很接近了。

我会在这里发布我的实现,以防人们需要它(从与您相同的来源移植)

公共类算法
{
静态双calcSunrise(整年日期、双本地偏移、双纬度、双经度)
{
返回计算值(dayOfYear、localOffset、纬度、经度、true);
}
静态双calcSunset(整年日期、双本地偏移、双纬度、双经度)
{
返回计算值(dayOfYear、localOffset、纬度、经度、false);
}
// http://williams.best.vwh.net/sunrise_sunset_algorithm.htm
静态双计算(int dayOfYear,双本地偏移,双纬度,双经度,布尔上升)
{
//1.首先计算一年中的哪一天
//int N1=楼层(275*月/9.0);
//int N2=楼层((月+9)/12.0);
//int N3=(1+楼层((年份-4*楼层(年份/4.0)+2)/3.0));
//int N=N1-(N2*N3)+第30天;
int N=一年中的某一天;
//2.将经度转换为小时值并计算近似时间
双高=经度/15;
双t=上升?
N+((6-lngHour)/24):
N+((18-lngHour)/24);
//3.计算太阳的平均异常
双M=(0.9856*t)-3.289;
//4.计算太阳的真实经度
双L=M+(1.916*sin(M))+(0.020*sin(2*M))+282.634;
L=模(L,360);
//5a.计算太阳的赤经
双RA=atan(0.91764*tan(L));
RA=mod(RA,360);
//5b.赤经值需要与L位于同一象限
双象限=(楼层(L/90))*90;
双象限=(楼层(RA/90))*90;
RA=RA+(1象限-RA象限);
//5c.赤经值需要转换成小时
RA=RA/15;
//6.计算太阳的赤纬
双sinDec=0.39782*sin(L);
双cosDec=cos(asin(sinDec));
//7a.计算太阳的本地时角
双天顶=90+50.0/60;
双余弦=(余弦(天顶)-(sinDec*sin(纬度))/(余弦*余弦(纬度));
如果(cosH>1)
抛出新错误(“太阳永远不会在该位置升起(在指定日期”);
如果(cosH<-1)
抛出新错误(“太阳永远不会在该位置(指定日期)落下”);
//7b.完成H的计算并转换为小时
双H=上升?
360-acos(cosH):
acos(cosH);
H=H/15;
//8.计算本地平均上升/设定时间
双T=H+RA-(0.06571*T)-6.622;
//9.调整回UTC
双UT=T-lngHour;
//10.将UT值转换为纬度/经度的本地时区
双localT=UT+localOffset;
localT=mod(localT,24);
返回localT;
}
静态整数层(双d){return(int)Math.floor(d);}
静态双正弦(双阶)
{
返回Math.sin(度*Math.PI/180);
}
静态双余弦(双度)
{
返回Math.cos(degree*Math.PI/180);
}
静态双棕褐色(双度)
{
返回Math.tan(度*Math.PI/180);
}
静态双atan(双x)
{
返回Math.atan(x)*180/Math.PI;
}
静态双asin(双x)
{
返回Math.asin(x
    public class SunRiseSetAlgo
    {
        static double calcSunrise(int dayOfYear, double localOffset, double latitude, double longitude)
        {
            return calc(dayOfYear, localOffset, latitude, longitude, true);
        }
        static double calcSunset(int dayOfYear, double localOffset, double latitude, double longitude)
        {
            return calc(dayOfYear, localOffset, latitude, longitude, false);
        }

        // http://williams.best.vwh.net/sunrise_sunset_algorithm.htm
        static double calc(int dayOfYear, double localOffset, double latitude, double longitude, boolean rise)
        {
            //1. first calculate the day of the year

    //        int N1 = floor(275 * month / 9.0);
    //        int N2 = floor((month + 9) / 12.0);
    //        int N3 = (1 + floor((year - 4 * floor(year / 4.0) + 2) / 3.0));
    //        int N = N1 - (N2 * N3) + day - 30;
            int N = dayOfYear;

            //2. convert the longitude to hour value and calculate an approximate time

            double lngHour = longitude / 15;
            double t = rise?
                N + (( 6 - lngHour) / 24) :
                N + ((18 - lngHour) / 24);

            //3. calculate the Sun's mean anomaly

            double M = (0.9856 * t) - 3.289;

            //4. calculate the Sun's true longitude

            double L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634;
            L = mod(L, 360);

            //5a. calculate the Sun's right ascension
            double RA = atan(0.91764 * tan(L));
            RA = mod(RA, 360);

            //5b. right ascension value needs to be in the same quadrant as L
            double Lquadrant  = (floor( L/90)) * 90;
            double RAquadrant = (floor(RA/90)) * 90;
            RA = RA + (Lquadrant - RAquadrant);

            //5c. right ascension value needs to be converted into hours
            RA = RA / 15;

            //6. calculate the Sun's declination
            double sinDec = 0.39782 * sin(L);
            double cosDec = cos(asin(sinDec));

            //7a. calculate the Sun's local hour angle
            double zenith = 90 + 50.0/60;
            double cosH = (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude));

            if (cosH >  1)
              throw new Error("the sun never rises on this location (on the specified date");
            if (cosH < -1)
              throw new Error("the sun never sets on this location (on the specified date");

            //7b. finish calculating H and convert into hours
            double H = rise?
                360 - acos(cosH) :
                acos(cosH);
            H = H / 15;

            //8. calculate local mean time of rising/setting
            double T = H + RA - (0.06571 * t) - 6.622;

            //9. adjust back to UTC
            double UT = T - lngHour;

            //10. convert UT value to local time zone of latitude/longitude
            double localT = UT + localOffset;
            localT = mod(localT, 24);
            return localT;
        }

        static int floor(double d){ return (int)Math.floor(d); }

        static double sin(double degree)
        {
            return Math.sin(degree*Math.PI/180);
        }
        static double cos(double degree)
        {
            return Math.cos(degree*Math.PI/180);
        }
        static double tan(double degree)
        {
            return Math.tan(degree*Math.PI/180);
        }
        static double atan(double x)
        {
            return Math.atan(x) *180/Math.PI;
        }
        static double asin(double x)
        {
            return Math.asin(x) *180/Math.PI;
        }
        static double acos(double x)
        {
            return Math.acos(x) *180/Math.PI;
        }

        static double mod(double x, double lim)
        {
            return x - lim * floor(x/lim);
        }

    }