我找到了計算第二個座標here的公式。但是當我將它轉換爲Java時,結果並不如我預期的那樣。Java - 根據給定的座標,方位和距離計算第二個座標
private Point get(double lat1, double lon1, double tc, int d) {
double lat = Math.asin(
Math.sin(lat1) * Math.cos(d)
+ Math.cos(lat1) * Math.sin(d) * Math.cos(tc)
);
double dlon= Math.atan2(
Math.sin(tc) * Math.sin(d) * Math.cos(lat1)
, Math.cos(d) - Math.sin(lat1) * Math.sin(lat));
double lon = ((lon1 - dlon + Math.PI) % (2 * Math.PI)) - Math.PI;
return new Point(lat, lon);
}
我測試了上面的代碼,用get(50,10,0,0)等簡單的例子。因此,預計結果將作爲第一個點作爲相同,但是這是我得到的結果是:用正確的公式來計算第二座標
Lat: 1.4432701894877245, lon: -3.8108244707674395
我是誰?
[編輯] 這裏是我嘗試轉換爲Java代碼中的公式
lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat))
lon=mod(lon1-dlon +pi,2*pi)-pi
爲什麼d是int? –
tc的單位是弧度,d是km。我不認爲主要類型會影響這個算法的結果。 – Hien
我認爲你的公式出了問題,因爲cos(d)沒有任何意義。 – talex