2017-10-05 9 views
0

で2点間にベアリング私は、入力フォーマットは52.070564でポイント2 までポイント1から方位を計算したい - どんなに私は正しい出力を得ることができませんしてみてください何4.407116計算ではJavaScript

私が使用する式は次のとおりです。

// koers berekenen 
 
var y = Math.sin(ln-ln1) * Math.cos(lt); 
 
var x = Math.cos(lt1)*Math.sin(lt) - 
 
     Math.sin(lt1)*Math.cos(lt)*Math.cos(ln-ln1); 
 
var radians = Math.atan2(y, x); 
 
var bearing = Math.round(radians * (180/Math.PI)); 
 

 
/* >>>>>> original <<<<<<< 
 
var y = Math.sin(λ2-λ1) * Math.cos(φ2); 
 
var x = Math.cos(φ1)*Math.sin(φ2) - 
 
     Math.sin(φ1)*Math.cos(φ2)*Math.cos(λ2-λ1); 
 
var brng = Math.atan2(y, x).toDegrees(); 
 

 
φ1,λ1 is the start point, φ2,λ2 the end point (Δλ is the difference in longitude) 
 
*/

+0

あなたは私たちにいくつかの例の入力と出力例を与えることができますか? –

+0

'Math.sin()'と 'Math.cos()'は入力がラジアンであると想定しています。あなたの入力は度なので、変換する必要があります。 – Barmar

+0

@Rogierは私のソリューションをチェックします – krishnar

答えて

0

start_latitude = 12.9389352 
 
start_longitude = 77.6994306 
 
stop_latitude = 12.939103 
 
stop_longitude = 77.705825 
 

 
var y = Math.sin(stop_longitude-start_longitude) * Math.cos(stop_latitude); 
 
var x = Math.cos(start_latitude)*Math.sin(stop_latitude) - 
 
     Math.sin(start_latitude)*Math.cos(stop_latitude)*Math.cos(stop_longitude-start_longitude); 
 
var brng = Math.atan2(y, x) * 180/Math.PI; 
 

 

 
alert("Bearing in degreee: " + brng);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+0

のベアリングを与える必要がありますので、私の入力はラジアンでなければなりませんか?私はこれを変換する方法を見つけようとします。ありがとう! – Rogier

+0

私はまだ試しましたが、期待した結果はありませんでした。私は(* Math.PI/180)で入力を度から半径に変更します。私は2点を取ると、1つは私の庭であり、もう1つは通りの反対側にあります。私は20のベアリングを得ます。しかし、私は私のiPhoneでコンパスを取得すると、その点までのベアリングは250です。私は間違いを犯していますか?思考で??? – Rogier