我工作的一個天文數據庫程序,允許用戶創建並輸入自己的恆星和褐矮星,除其他事項外,對於一款入門級編程課程在大學。每個對象都有確定其在空間中的位置,與太陽處於0,0,0光年XYZ座標。然而,由於大量的星形數據庫(例如SIMBAD),維基百科等以視差角度和赤經/赤緯座標給出了天文物體的位置,所以我給了用戶使用添加物體的選項這些參數,如果他們沒有xyz座標。儘管如此,我仍然無法提供準確的值。獲得錯誤的距離在Java中
下面是進入視差角碼,與選項/進入兩個角秒爲和毫弧秒/ 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();
}
這兩種給出正確的結果(即3.26167/(angle in as)
),當我添加一個額外的println語句在計算後檢查dist的值。例如,輸入Sirius'視差(0.37921爲,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 /月值用於計算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(使用維基百科上列出的視差和RA/Dec)的距離爲5.139 ly,而不是使用單獨的視差計算的8.60 ly值。我也越來越低估了更遙遠的事情,比如一個對象,應爲〜388光年遠是幾十光年近。
我實在看不出它可能出現了問題,雖然任何地方。特只有我能想到的事情是RA /月進入H/M或d/M當覆蓋雙打int類型,和我固定在初期(這是造成更大的錯誤)。有什麼我在這裏失蹤?也許只是使用雙打而不是長時間的損失。
爾加,僅此而已。不知道我是如何錯過的,我三重檢查了該部分。現在給了Sirius 8.601。謝謝! – cDef
適應我們最好的。有時你只需要第二雙眼睛。 –