0

このサイトの機能を実装しようとしました。

φ2 = asin( sin(φ1)*cos(d/R) + cos(φ1)*sin(d/R)*cos(θ) )

λ2 = λ1 + atan2( sin(θ)*sin(d/R)*cos(φ1), cos(d/R)−sin(φ1)*sin(φ2))

//import static  java.lang.Math.*;      
public static LatLng fromBearingDistance(double lat1, double lon1, double brng, double d) {     
    double R = 6371.0;      
    double lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + 
              Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
    double lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
                     Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
    return new LatLng(lat2,lon2);   
}

私の関数の結果は次のとおり0.0905,1.710です53.188 0.133

fromBearingDistance(53.32055555555556f, 1.7297222222222224f,
        96.02166666666666f, 124.8f);

これは、サンプル サイトと同じ座標です。

ここで何が起こっているのでしょうか?- コードは、文字通り、似ています。私が変更したのは、vars から doubles だけです。

このサイトを使用して、度から小数に変換しました。

4

1 に答える 1

2

問題の一部は、緯度、経度、方位の値が度単位で表示されているのに、リンクしたページの数式ではラジアン単位であることが求められていることにあると思います。ページを一番下に向かってスクロールすると、ページの作成者はLatLon、場所を表すオブジェクトのメソッドとして、計算の JavaScript 実装を実際に提供しています。これは、あなたがやろうとしていることと一致すると思われる方法です。計算の前に彼が最初に行うことは、すべてをラジアンに変換することであり、最後に行うことは度に戻すことに注意してください。

/**
 * Returns the destination point from this point having travelled the given distance
 * (in km) on the given initial bearing (bearing may vary before destination is reached)
 *
 *   see http://williams.best.vwh.net/avform.htm#LL
 *
 * @param   {Number} brng: Initial bearing in degrees
 * @param   {Number} dist: Distance in km
 * @returns {LatLon} Destination point
 */
LatLon.prototype.destinationPoint = function(brng, dist) 
{
  dist = typeof(dist)=='number' ? dist : typeof(dist)=='string' && dist.trim()!='' ? +dist : NaN;
  dist = dist/this._radius;  // convert dist to angular distance in radians
  brng = brng.toRad();  // 
  var lat1 = this._lat.toRad(), lon1 = this._lon.toRad();

  var lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) + 
                        Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) );
  var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1), 
                               Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2));
  lon2 = (lon2+3*Math.PI) % (2*Math.PI) - Math.PI;  // normalise to -180..+180º

  return new LatLon(lat2.toDeg(), lon2.toDeg());
}

このjava.lang.Mathクラスには、度とラジアンを相互に変換するためのメソッドがあるため、それらを使用してコードを改造するのは非常に簡単です。

于 2013-03-19T04:54:29.337 に答える