Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.
Function GreatArcDistance(Lat1 As Double, Lon1 As Double, Lat2 As Double, Lon2 As Double, Radius As Double) As Double
'
' Calculates the Great Arc (shortest) distance between 2 locations on the globe.
'
' Uses functions from Trigonometry
'
Dim X1 As Double, Y1 As Double, Z1 As Double, X2 As Double, Y2 As Double, Z2 As Double
Dim CosX As Double, ChordLen As Double
LatLongToXYZ Lat1, Lon1, Radius, X1, Y1, Z1
LatLongToXYZ Lat2, Lon2, Radius, X2, Y2, Z2
ChordLen = Sqr((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2) + (Z1 - Z2) * (Z1 - Z2))
CosX = 1 - ChordLen * ChordLen / (2 * Radius * Radius)
Debug.Print X1, Y1, Z1
Debug.Print X2, Y2, Z2
Debug.Print ChordLen, CosX
If CosX = 1 Or CosX = -1 Then
GreatArcDistance = 0
Else
GreatArcDistance = Sqr(1 - CosX * CosX) * Radius * PI() / 2
End If
End Function
Sub LatLongToXYZ(Lat As Double, Lon As Double, Radius As Double, x As Double, y As Double, z As Double)
'
' Converts Latitude, Longitude, Radius to 3d-Cartesian coordinates
'
' Assumes:
' X axis runs through 270 (-X) and 90 (+X) Latitude
' Y axis runs North (+Y) to South (-Y)
' Z axis runs through 0 (-Z) and 180 (+Z) Latitude
'
y = Radius * Sin(Deg2Rad(Lat))
x = Radius * Sin(Deg2Rad(Lon)) * Cos(Deg2Rad(Lat))
z = -Radius * Cos(Deg2Rad(Lon)) * Cos(Deg2Rad(Lat))
End Sub
Function Deg2Rad(x As Double) As Double
' Degrees to radians
Deg2Rad = x / 180 * PI()
End Function
Function PI() As Double
PI = Atn(1) * 4
End Function
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
How to get many filtered in Excel 2010? | 7 | 31 | |
sql statement - | 9 | 24 | |
Outlook 2016 - Change time of existing recurring appointment | 2 | 19 | |
MS Access 2010 Close Form Event - Stop Form Closing | 4 | 27 |
Join the community of 500,000 technology professionals and ask your questions.