Gladir.com - LotusScript - Calcul la distance entre deux coordonnées de Longitude et Latitude


Une des fonctions les plus communes de la géographie et des systèmes modernes, c'est le calcul de la distance géographique entre deux coordonnées de Longitude et de Latitude. Il n'y a aucune nécessité de grande connaissance en trigonométrie pour arriver à se genre de calcul dans le format qu'on le souhaite, Km, Miles ou Miles Nautiques. Ainsi, si vous savez les coordonnéss suivantes:
Ville Latitude Longitude
Montréal 45 31N 73 34O
Paris 48 50N 2 20E
A l'aide du code source LotusScript suivant, vous trouvez la réponse que vous souhaitez:
Sub Main
     Print "Distance entre Montréal et Paris en Km: " + Str$(CoordToDeltaKm(45, 31, "N", 73, 34, "O", 48, 50, "N", 2, 20, "E"))
     Print "Distance entre Montréal et Paris en Miles: " + Str$(CoordToDeltaStatuteMiles(45, 31, "N", 73, 34, "O", 48, 50, "N", 2, 20, "E"))
     Print "Distance entre Montréal et Paris en Miles Nautique: " + Str$(CoordToDeltaNauticalMiles(45, 31, "N", 73, 34, "O", 48, 50, "N", 2, 20, "E")) 
End Sub

Function CoordToDeltaKm( _
Byval Q1Latitude As Double, Byval Q1LatiDeg As Double, Byval Q1LatiDirection As String, _
Byval Q1Longitude As Double, Byval Q1LongDeg As Double, Byval Q1LongDirection As String, _
Byval Q2Latitude As Double, Byval Q2LatiDeg As Double, Byval Q2LatiDirection As String, _
Byval Q2Longitude As Double, Byval Q2LongDeg As Double, Byval Q2LongDirection As String) As Double
     Dim a1, b1, a2, b2, RawDelta As Double
     a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Pi / 180
     If Q1LatiDirection = "N" Then
          a1 = -a1
     End If
     b1 = (Q1Longitude + (Q1LongDeg / 60)) * Pi / 180
     If Q1LongDirection = "O" Then
          b1 = -b1
     End If
     a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Pi / 180
     If Q2LatiDirection = "N" Then
          a2 = -a2
     End If
     b2 = (Q2Longitude + (Q2LongDeg / 60)) * Pi / 180
     If Q2LongDirection = "O" Then
          b2 = -b2
     End If
     RawDelta = Acos(Cos(a1) * Cos(b1) * Cos(a2) * Cos(b2) + Cos(a1) * Sin(b1) * Cos(a2) * Sin(b2) + Sin(a1) * Sin(a2))
     CoordToDeltaKm = RawDelta * 6378.0
End Function

Function CoordToDeltaNauticalMiles( _
Byval Q1Latitude As Double, Byval Q1LatiDeg As Double, Byval Q1LatiDirection As String, _
Byval Q1Longitude As Double, Byval Q1LongDeg As Double, Byval Q1LongDirection As String, _
Byval Q2Latitude As Double, Byval Q2LatiDeg As Double, Byval Q2LatiDirection As String, _
Byval Q2Longitude As Double, Byval Q2LongDeg As Double, Byval Q2LongDirection As String) As Double
     Dim a1, b1, a2, b2, RawDelta As Double
     a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Pi / 180
     If Q1LatiDirection = "N" Then
          a1 = -a1
     End If
     b1 = (Q1Longitude + (Q1LongDeg / 60)) * Pi / 180
     If Q1LongDirection = "O" Then
          b1 = -b1
     End If
     a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Pi / 180
     If Q2LatiDirection = "N" Then
          a2 = -a2
     End If
     b2 = (Q2Longitude + (Q2LongDeg / 60)) * Pi / 180
     If Q2LongDirection = "O" Then
          b2 = -b2
     End If
     RawDelta = Acos(Cos(a1) * Cos(b1) * Cos(a2) * Cos(b2) + Cos(a1) * Sin(b1) * Cos(a2) * Sin(b2) + Sin(a1) * Sin(a2))
     CoordToDeltaNauticalMiles = RawDelta * 3443.9
End Function 

Function CoordToDeltaStatuteMiles( _
Byval Q1Latitude As Double, Byval Q1LatiDeg As Double, Byval Q1LatiDirection As String, _
Byval Q1Longitude As Double, Byval Q1LongDeg As Double, Byval Q1LongDirection As String, _
Byval Q2Latitude As Double, Byval Q2LatiDeg As Double, Byval Q2LatiDirection As String, _
Byval Q2Longitude As Double, Byval Q2LongDeg As Double, Byval Q2LongDirection As String) As Double
     Dim a1, b1, a2, b2, RawDelta As Double
     a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Pi / 180
     If Q1LatiDirection = "N" Then
          a1 = -a1
     End If
     b1 = (Q1Longitude + (Q1LongDeg / 60)) * Pi / 180
     If Q1LongDirection = "O" Then
          b1 = -b1
     End If
     a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Pi / 180
     If Q2LatiDirection = "N" Then
          a2 = -a2
     End If
     b2 = (Q2Longitude + (Q2LongDeg / 60)) * Pi / 180
     If Q2LongDirection = "O" Then
          b2 = -b2
     End If
     RawDelta = Acos(Cos(a1) * Cos(b1) * Cos(a2) * Cos(b2) + Cos(a1) * Sin(b1) * Cos(a2) * Sin(b2) + Sin(a1) * Sin(a2))
     CoordToDeltaStatuteMiles = RawDelta * 3963.1
End Function
on obtiendra le résultat suivant:
Distance entre Montréal et Paris en Km: 5510.16761889
Distance entre Montréal et Paris en Miles: 3423.85470217
Distance entre Montréal et Paris en Miles Nautique: 2975.30044884


Dernière mise à jour: Mardi, le 7 février 2006