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ées suivantes :
Ville | Latitude | Longitude |
---|---|---|
Montréal | 45 31N | 73 34O |
Paris | 48 50N | 2 20E |
A l'aide du code source ASP.NET (VB.NET) suivant, vous trouvez la réponse que vous souhaitez :
- <%@ Page Language="VB" %>
- <script runat="server">
- Function CoordToDeltaKm( _
- Q1Latitude As Double, Q1LatiDeg As Double, Q1LatiDirection As Char, _
- Q1Longitude As Double, Q1LongDeg As Double, Q1LongDirection As Char, _
- Q2Latitude As Double, Q2LatiDeg As Double, Q2LatiDirection As Char, _
- Q2Longitude As Double, Q2LongDeg As Double, Q2LongDirection As Char) As Double
- Dim a1, b1, a2, b2, RawDelta As Double
- a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180
- If Q1LatiDirection = "N" Then
- a1 = -a1
- End If
- b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180
- If Q1LongDirection = "O" Then
- b1 = -b1
- End If
- a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180
- If Q2LatiDirection = "N" Then
- a2 = -a2
- End If
- b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180
- If Q2LongDirection = "O" Then
- b2 = -b2
- End If
- RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2))
- CoordToDeltaKm = RawDelta * 6378.0
- End Function
-
- Function CoordToDeltaStatuteMiles( _
- Q1Latitude As Double, Q1LatiDeg As Double, Q1LatiDirection As Char, _
- Q1Longitude As Double, Q1LongDeg As Double, Q1LongDirection As Char, _
- Q2Latitude As Double, Q2LatiDeg As Double, Q2LatiDirection As Char, _
- Q2Longitude As Double, Q2LongDeg As Double, Q2LongDirection As Char) As Double
- Dim a1, b1, a2, b2, RawDelta As Double
- a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180
- If Q1LatiDirection = "N" Then
- a1 = -a1
- End If
- b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180
- If Q1LongDirection = "O" Then
- b1 = -b1
- End If
- a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180
- If Q2LatiDirection = "N" Then
- a2 = -a2
- End If
- b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180
- If Q2LongDirection = "O" Then
- b2 = -b2
- End If
- RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2))
- CoordToDeltaStatuteMiles = RawDelta * 3963.1
- End Function
-
-
- Function CoordToDeltaNauticalMiles( _
- Q1Latitude As Double, Q1LatiDeg As Double, Q1LatiDirection As Char, _
- Q1Longitude As Double, Q1LongDeg As Double, Q1LongDirection As Char, _
- Q2Latitude As Double, Q2LatiDeg As Double, Q2LatiDirection As Char, _
- Q2Longitude As Double, Q2LongDeg As Double, Q2LongDirection As Char) As Double
- Dim a1, b1, a2, b2, RawDelta As Double
- a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180
- If Q1LatiDirection = "N" Then
- a1 = -a1
- End If
- b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180
- If Q1LongDirection = "O" Then
- b1 = -b1
- End If
- a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180
- If Q2LatiDirection = "N" Then
- a2 = -a2
- End If
- b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180
- If Q2LongDirection = "O" Then
- b2 = -b2
- End If
- RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2))
- CoordToDeltaNauticalMiles = RawDelta * 3443.9
- End Function
- </script>
- <%
- Response.Write("Distance entre Montréal et Paris en Km: " &CStr(CoordToDeltaKm(45, 31,"N",73, 34,"O",48, 50,"N", 2, 20,"E")) &"<BR>")
- Response.Write("Distance entre Montréal et Paris en Miles: " &CStr(CoordToDeltaStatuteMiles(45, 31,"N", 73, 34,"O", 48, 50,"N", 2, 20,"E")) &"<BR>")
- Response.Write("Distance entre Montréal et Paris en Miles Nautique: " &CStr(CoordToDeltaNauticalMiles(45, 31,"N", 73, 34,"O", 48, 50,"N", 2, 20,"E")) &"<BR>")
- %>
ou en version ASP.NET (C# (C Sharp)) :
- <%@ Page Language="C#" %>
- <script runat="server">
- static double CoordToDeltaKm(
- double Q1Latitude, double Q1LatiDeg, char Q1LatiDirection,
- double Q1Longitude, double Q1LongDeg, char Q1LongDirection,
- double Q2Latitude, double Q2LatiDeg, char Q2LatiDirection,
- double Q2Longitude, double Q2LongDeg, char Q2LongDirection
- )
- {
- double a1, b1, a2, b2, RawDelta;
- a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180;
- if (Q1LatiDirection == 'N') a1 = -a1;
- b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180;
- if (Q1LongDirection == 'O') b1 = -b1;
- a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180;
- if (Q2LatiDirection == 'N') a2 = -a2;
- b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180;
- if (Q2LongDirection == 'O') b2 = -b2;
- RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2));
- return RawDelta * 6378.0;
- }
-
- static double CoordToDeltaStatuteMiles(
- double Q1Latitude, double Q1LatiDeg, char Q1LatiDirection,
- double Q1Longitude, double Q1LongDeg, char Q1LongDirection,
- double Q2Latitude, double Q2LatiDeg, char Q2LatiDirection,
- double Q2Longitude, double Q2LongDeg, char Q2LongDirection
- )
- {
- double a1, b1, a2, b2, RawDelta;
- a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180;
- if (Q1LatiDirection == 'N') a1 = -a1;
- b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180;
- if (Q1LongDirection == 'O') b1 = -b1;
- a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180;
- if (Q2LatiDirection == 'N') a2 = -a2;
- b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180;
- if (Q2LongDirection == 'O') b2 = -b2;
- RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2));
- return RawDelta * 3963.1;
- }
-
- static double CoordToDeltaNauticalMiles(
- double Q1Latitude, double Q1LatiDeg, char Q1LatiDirection,
- double Q1Longitude, double Q1LongDeg, char Q1LongDirection,
- double Q2Latitude, double Q2LatiDeg, char Q2LatiDirection,
- double Q2Longitude, double Q2LongDeg, char Q2LongDirection
- )
- {
- double a1, b1, a2, b2, RawDelta;
- a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180;
- if (Q1LatiDirection == 'N') a1 = -a1;
- b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180;
- if (Q1LongDirection == 'O') b1 = -b1;
- a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180;
- if (Q2LatiDirection == 'N') a2 = -a2;
- b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180;
- if (Q2LongDirection == 'O') b2 = -b2;
- RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2));
- return RawDelta * 3443.9;
- }
- </script>
- <%
- Response.Write("Distance entre Montréal et Paris en Km: " + CoordToDeltaKm(45, 31,'N',73, 34,'O',48, 50,'N', 2, 20,'E') + "<BR>");
- Response.Write("Distance entre Montréal et Paris en Miles: " + CoordToDeltaStatuteMiles(45, 31,'N', 73, 34,'O', 48, 50,'N', 2, 20,'E') + "<BR>");
- Response.Write("Distance entre Montréal et Paris en Miles Nautique: " + CoordToDeltaNauticalMiles(45, 31,'N', 73, 34,'O', 48, 50,'N', 2, 20,'E') + "<BR>");
- %>
on obtiendra le résultat suivant :
Distance entre Montréal et Paris en Km: 5510.16761889Distance entre Montréal et Paris en Miles: 3423.85470217
Distance entre Montréal et Paris en Miles Nautique: 2975.30044884
Voir également
Langage de programmation - Visual Basic .NET (VB .NET) - Calcul la distance entre deux coordonnées de Longitude et Latitude
Langage de programmation - C# (C Sharp) - Calcul la distance entre deux coordonnées de Longitude et Latitude