-1
我試圖建立一個沒有圖書館的ISS跟蹤器......迄今爲止這麼好。但是我得到使用本網站的ISS的座標:https://api.wheretheiss.at/v1/satellites/25544計算笛卡爾座標系或極座標系中2個位置之間的夾角
從經度和緯度,現在需要計算兩個角度: 角度一個是地上0-180°的伺服高程。 角度二是步進電機(0-360°)相對於北極的旋轉。
我已經有一些Java代碼來嘗試它,但它不會工作。我收到了奇怪的結果。例如:國際空間站位於我的正上方(400公里;經度和緯度相同),角度爲:141.68°和135.28°
Ps:因此這是一個使用圖書館的學校項目不是一個選項...
public class Main {
public static void main(String[] args) {
//double issR = 6371 + 410.92521771305;
double issR = 6741;
double issLat = 58.190897;
double issLong = -30.585309;
//posR = height in km + earth radius
//posLat = position latitude in °(deg)
//posLong = position longitude in °(deg)
double posR = 6365.092;
double posLat = 58.190897;
double posLong = -30.585309;
//Convert to cartesian
double issX = issR * Math.sin(issLat) * Math.cos(issLong);
double issY = issR * Math.sin(issLat) * Math.sin(issLong);
double issZ = issR * Math.cos(issLat);
System.out.println("ISS\nx: " + issX);
System.out.println("y: " + issY);
System.out.println("z: " + issZ);
//Convert to cartesian
double posX = posR * Math.sin(posLat) * Math.cos(posLong);
double posY = posR * Math.sin(posLat) * Math.sin(posLong);
double posZ = posR * Math.cos(posLat);
System.out.println("\nPOS\nx: " + posX);
System.out.println("y: " + posY);
System.out.println("z: " + posZ);
//Calculate angle (I'm not sure which angle is which :D)
double angleYZ = Math.atan2(issY - posY, issZ - posZ)*180/Math.PI;
double angleYX = Math.atan2(issY - posY, issX - posX)*180/Math.PI;
//Another try to calculate the angle...
double angle = Math.toDegrees(Math.atan2(Math.sqrt(Math.pow(issX - posX, 2) + Math.pow(issY - posY, 2)), issZ - posZ))+90d;
double angle2 = Math.toDegrees(Math.atan2(Math.sqrt(Math.pow(issX - posX, 2) + Math.pow(issY - posY, 2)), issX - posX))+90d;
System.out.println();
System.out.println("Angle X: " + angleYZ);
System.out.println("Angle Z: " + angleYX);
System.out.println(angle);
System.out.println(angle2);
}
}
class Math {
final static double PI = java.lang.Math.PI;
public static double cos(double x) {
return java.lang.Math.cos(x * Math.PI/180.0);
}
public static double sin(double x) {
return java.lang.Math.sin(x * Math.PI/180.0);
}
public static double atan2(double x, double y) {
return java.lang.Math.atan2(x, y);
}
public static double toDegrees(double angrad) {
return java.lang.Math.toDegrees(angrad);
}
public static double pow(double a, double b) {
return java.lang.Math.pow(a, b);
}
public static double sqrt(double a) {
return java.lang.Math.sqrt(a);
}
}
假設你改變你的ATAN2使用相同的角度單位爲你的正弦和餘弦函數,我覺得傾斜角度'ATAN2( issR * cos(issLat - posLat) - posR,issR * sin(issLat - posLat))'(0爲北向水平,90度向上,180度es爲南向,-90度爲向下),平移角爲atan2(issR * sin(issLong - posLong),issR * cos(issLong - posLong) - posR)'(0爲北,90度爲東, 180度爲南,-90度爲西)。但我可能是錯的。 –
你是我的英雄!它非常好,非常感謝你! – LsHallo