Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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中输入天体坐标和视差时获取错误的距离_Java_Math_Trigonometry_Astronomy - Fatal编程技术网

在Java中输入天体坐标和视差时获取错误的距离

在Java中输入天体坐标和视差时获取错误的距离,java,math,trigonometry,astronomy,Java,Math,Trigonometry,Astronomy,我正在开发一个天文数据库程序,允许用户创建并输入他们自己的恒星和褐矮星,以及其他东西,用于大学的入门级编程课程。每个物体都有xyz坐标,以确定其在空间中的位置,太阳位于0、0、0光年 然而,由于许多恒星数据库(如SIMBAD)、Wikipedia等,根据视差角和赤经/赤纬坐标给出了天文物体的位置,我给用户提供了使用这些参数添加物体的选项,以防它们没有xyz坐标。但是,我在让它提供准确的值方面遇到了问题 以下是输入视差角度的代码,以及输入arcseconds/as和毫arcseconds/mas的

我正在开发一个天文数据库程序,允许用户创建并输入他们自己的恒星和褐矮星,以及其他东西,用于大学的入门级编程课程。每个物体都有xyz坐标,以确定其在空间中的位置,太阳位于0、0、0光年

然而,由于许多恒星数据库(如SIMBAD)、Wikipedia等,根据视差角和赤经/赤纬坐标给出了天文物体的位置,我给用户提供了使用这些参数添加物体的选项,以防它们没有xyz坐标。但是,我在让它提供准确的值方面遇到了问题

以下是输入视差角度的代码,以及输入arcseconds/as和毫arcseconds/mas的选项:

/**
 * Notes:
 * scReadIntMM(n1, n2); reads and returns user-entered ints within the range n1 to n2, via Scanner
 * scReadDoubleMM(n1, n2); is the same, only for doubles.
 */

//user chooses units for entering parallax
System.out.println("Entering parallax and RA/Dec coordinates.");
System.out.println();
System.out.println("Which units do you wish to use?");
System.out.println("(1) Arcseconds (1 as = 1/3600 degrees)");
System.out.println("(2) Milliarcseconds (1 mas = 1/1000 arcseconds)");
userChoice = scReadIntMM(1, 2);  //stores user choice
System.out.println();

//user enters angle, converts to distance and stores
if (userChoice == 1){
    //if user chose to enter in arcseconds
    System.out.println("Set object's parallax angle, in arcseconds.");
    System.out.println("Maximum: 3.26167 (corresponding to a distance of exactly 1 light year)");
    System.out.println("Minimum: 0.006523266 (corresponding to a distance of about 500 light years)");
    dist = (3.26167 / (scReadDoubleMM(0.006523266, 3.26167)));
    System.out.println();

} else if (userChoice == 2){
    //if user chose to enter in milliarcseconds
    System.out.println("Set object's parallax angle, in milliarcseconds.");
    System.out.println("Maximum: 3261.67 (corresponding to a distance of exactly 1 light year)");
    System.out.println("Minimum: 6.523266 (corresponding to a distance of about 500 light years)");
    dist = (3.26167 / ((scReadDoubleMM(6.523266, 3261.67)) / 1000));
    System.out.println();
}
当我在计算后添加一个额外的println语句来检查dist的值时,这两个语句都给出了正确的结果(即
3.26167/(as中的角度)
)。例如,输入视差(0.37921as,379.21mas)的值为8.60光年,这正是我在维基百科页面上看到的

下一个阶段似乎是一切都出了问题。在这一部分中,用户输入坐标,使用上列出的步骤将坐标转换为度,然后在输入所有内容后将坐标更改为弧度:

//user enters right ascension
System.out.println("Enter hours of right ascension. (Must be between 0 and 23, whole");
System.out.println("numbers only.)");
ra = (((double)scReadIntMM(0, 23)) * 15.0);  //enters hours
System.out.println();
System.out.println("Enter minutes of right ascension. (Must be between 0 and 59, whole");
System.out.println("numbers only.)");
ra = ra + (((double)scReadIntMM(0, 59) / 60.0) * 15.0);  //enters mins
System.out.println();
System.out.println("Enter seconds of right ascension. (Must be between 0 and 59.999999.)");
ra = ra + ((scReadDoubleMM(0, 59.999999) / 3600.0) * 15.0);  //enters secs
ra = Math.toRadians(ra);  //converts from degrees to radians
System.out.println();

//user enters sign for declination (+ or -)
System.out.println("Is the object's declination positive or negative? (Enter a number.)");
System.out.println("(1) Positive");
System.out.println("(2) Negative");
userChoice = scReadIntMM(1, 2);  //stores dec sign
System.out.println();

//user enters declination
System.out.println("Enter degrees of declination, without positive or negative signs. (Must be");
System.out.println("between 0 and 90, whole numbers only.)");
dec = ((double)scReadIntMM(0, 90));  //enter degrees
System.out.println();
System.out.println("Enter minutes of declination. (Must be between 0 and 59, whole");
System.out.println("numbers only.)");
dec = dec + (((double)scReadIntMM(0, 59)) / 60.0);  //enter mins
System.out.println();
System.out.println("Enter seconds of declination. (Must be between 0 and 59.999999.)");
dec = dec + (scReadDoubleMM(0, 59.999999) / 3600.0);  //enter secs
dec = dec * userChoice;  //sets declination sign
dec = Math.toRadians(dec);  //converts from degrees to radians
System.out.println();
然后,RA/Dec值用于计算x、y、z值,仍然遵循我之前链接的页面上的说明:

//calculates x, y, z coords from ra/dec and distance values
xIn = ((dist * Math.cos(dec)) * Math.cos(ra));
yIn = ((dist * Math.cos(dec)) * Math.cos(ra));
zIn = (dist * Math.sin(dec));
使用这种方法,我得到了天狼星的距离为5.139 ly(使用维基百科上列出的视差和RA/Dec),而不是仅使用视差计算出的8.60 ly值。我还低估了更遥远的东西,比如一个距离约388 ly的物体离我们近几十ly


但我真的看不出有什么地方出了问题。我唯一能想到的是,在为RA/Dec输入H/M或D/M时,int值会覆盖double,我很早就解决了这个问题(这会导致更大的错误).这里有我遗漏的东西吗?可能是因为使用了双精度而不是长精度造成的损失。

从您发布的链接来看,尹应该是:

((dist * Math.cos(dec)) * Math.sin(ra));
而不是

((dist * Math.cos(dec)) * Math.cos(ra));

嘎,就是这样。不知道我怎么会错过,我三次检查了那个部分。现在天狼星得到了8.601 ly。谢谢!这是我们中最好的。有时候你只需要第二双眼睛。