2016-07-28 5 views
0

私はそれがこのようになります私は(第2メートル/中)で移動する2つの引数、新しい位置と速度を与えるようになる機能を作成するために設定速度で2ギガポイント間を移動するにはどうしたらいいですか?

をしようとしている:

func (l *Location) Move(newLoc *Location, speed float64) { 
    R := 6371.0 // Kilometers 
    lat1 := l.Latitude * math.Pi/180 
    lat2 := l.Longitude * math.Pi/180 
    diffLat := (newLoc.Latitude - l.Latitude) * math.Pi/180 
    diffLon := (newLoc.Longitude - l.Longitude) * math.Pi/180 

    a := math.Sin(diffLat/2)*math.Sin(diffLat/2) + 
     math.Cos(lat1)*math.Cos(lat2)*math.Sin(diffLon/2)*math.Sin(diffLon/2) 
    c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a)) 

    distanceToMove := R * c // Distance to travel in a straight line, in Kilometers 


} 

私が問題を抱えているのは、緯度をつけて現在の位置から始め、一定の時間をかけて新しい位置に来るという公式を考えているだけです。

緯度を56.65から58.12に変更し、私は1.3m/sで旅行するように指示しました。ありがとう。

+0

このメソッドは正確に何をすべきですか?機能の望ましい結果/副作用は何ですか? – Nebril

+0

@Nebril関数は基本的にループや他の方法で行う必要があるかどうかにかかわらず、ある場所から別の場所にGPS座標を徐々に移動することになっています。これを達成するための式や方法を理解できません – Datsik

+0

おそらく、位置を変更する時間枠を関数に伝えるために、Moveに3番目のパラメータを指定してください。 戻り値は新しい場所構造でなければなりません。これは 'l'から' newLoc'に 'speed'で移動するオブジェクトが新しい関数引数で指定された時間の後にある場所を含みます。 – Nebril

答えて

0

私はあなたの質問を理解すれば、1つの場所から2つの場所の間のすべての中間点を計算し、指定された速度で2つ目の中間点に移動することが目的です。

私が正しい場合は、次の方法で最初の解決策を得ることができます。誰かがこれを改善できるなら、私は感謝します。

On the proj4 documentationには、2点間の距離を計算する方法に関する多くの情報があります。

点AからBまでの速度(m/s)で始まることは、線AB上のAから距離mにある点A 'を各秒ごとに計算することを意味します。

Vincenty's formulaに基づく)より、アルゴリズムように

:私は、開始thatsの、任意のコメントがこの回答に感謝だと思い

func (l *Location) Move(newLoc *Location, speed float64) Location { 
    azimuthA, azimuthB, d := inverseVincenty(l, newLoc) 

    // Use the direct vincenty's formula. 
    // Here transform speed to get the correct value 
    // without transformation, since speed is in m/s, 
    // the resulting point will be at speed(m) distance from l. 
    res := directVincenty(l, speed, azimuthA) 

    // Now res shall contain your new point. 
    return res 
} 

func main() { 
    // init A and B and speed values. 
    C := A // to conserve A position. 
    t := time.Tick(1* time.Second) 
    for stop := false; !stop; { 
     select { 
      case <- t: 
      C = C.Move(B, speed) 
      case // here a break condition: 
       stop = true 
     } 
    } 
}