我正在研究一个天文数据库程序,该程序允许用户创建并输入他们自己的星星和褐矮星,以及其他东西,用于大学的入门级编程课程。每个物体都有xyz坐标,用于确定其在太空中的位置,太阳位于0,0 0光年。
然而,由于许多明星数据库(例如SIMBAD),维基百科等在视差角度和右上升/下降坐标方面给出了天文物体的位置,我已经给用户提供了使用这些来添加对象的选项。参数,如果它们没有xyz坐标。我遇到了提供准确值的问题。
以下是输入视差角的代码,可选择输入arcseconds / as和milliarcseconds / 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 / (angle in as)
)。例如,输入Sirius'视差(0.37921 as,379.21 mas给出的值为8.60光年,这正是我在查看维基百科页面后所期望的。
下一阶段似乎是一切都出错了。这部分是用户输入坐标的位置,使用this site上列出的程序将其转换为度数,然后在输入所有内容后更改为弧度:
//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));
使用这种方法,我对Sirius的距离为5.139(使用维基百科上列出的视差和RA / Dec),而不是仅使用视差计算的8.60 ly值。对于更遥远的事物,我也被低估了,就像一个物体应该距离几百个距离更近。
我真的看不到任何可能出错的地方。我唯一可以想到的是当输入H / M或D / M用于RA / Dec时,int值覆盖双倍,并且我在早期修复了它(它导致了更大的错误)。这里有什么我想念的吗?也许只是因为使用双打而不是长时间的损失。
答案 0 :(得分:0)
根据您发布的链接,似乎yIn应该是:
((dist * Math.cos(dec)) * Math.sin(ra));
而不是
((dist * Math.cos(dec)) * Math.cos(ra));