# GPS Intersecting radials using 2 know points and bearings • ### Question

• now have working VB Code

use 2 known GPS locations to find third GPS location based on true north bearing from known locations to target (third GPS Location).

```Imports System.Math

Public Class Form1

Dim Deg, Min As Integer
Dim R As Double = 6371
Dim MinSec, Sec, φ1, φ2, φ3, Δφ, Δλ, d, λ1, λ2, λ3, δ12, α1, α2 As Double

Function DegMinSec2DegDecimal(ByVal Deg As Double, ByVal Min As Double, ByVal Sec As Double)

Dim DD As Double = Deg + (Min / 60) + (Sec / 3600)
Return DD

End Function

Private Sub DegDecimal2DegMinSec(ByVal DecDeg As Double)

Deg = DecDeg
MinSec = (DecDeg Mod Deg) * 60
Min = MinSec
Sec = (MinSec Mod Min) * 60

End Sub

Private Sub AngularDist(ByVal Lat1 As Double, ByVal Lat2 As Double, ByVal Lon1 As Double, ByVal Lon2 As Double)

' Distance between 2 GPS Locations

Dim a As Double = Sin(Δφ / 2) * Sin(Δφ / 2) + Cos(φ1) * Cos(φ2) * Sin(Δλ / 2) * Sin(Δλ / 2)
Dim c As Double = 2 * Atan2(Sqrt(a), Sqrt(1 - a))
d = R * c

End Sub

Function BearingBetween2GPSLocations(ByVal Lat1 As Double, ByVal Lat2 As Double, ByVal Lon1 As Double, ByVal Lon2 As Double)

'where:  φ Is latitude, λ Is longitude

Dim y, x, brng As Double

y = Sin(λ2 - λ1) * Cos(φ2)
x = Cos(φ1) * Sin(φ2) - Sin(φ1) * Cos(φ2) * Cos(λ2 - λ1)
brng = ToDegrees(Atan2(y, x))

Return brng

End Function

Private Sub TargetGPSLocation(ByVal Pt1Lat, ByVal Pt1Lon, ByVal Pt1Brng, ByVal Pt2Lat, ByVal Pt2Lon, ByVal Pt2Brng)

'where Pt1 is GPS Location 1 and Pt2 is GPS Location 2, Brng is true north bearing to target (Pt3)

Dim θ13 As Double = ToRadians(Pt1Brng)
Dim θ23 As Double = ToRadians(Pt2Brng)

δ12 = 2 * Asin(Sqrt((Sin(Δφ / 2) ^ 2) + Cos(φ1) * Cos(φ2) * (Sin(Δλ / 2) ^ 2)))
Dim θa As Double = Acos((Sin(φ2) - Sin(φ1) * Cos(δ12)) / (Sin(δ12) * Cos(φ1)))
Dim θb As Double = Acos((Sin(φ1) - Sin(φ2) * Cos(δ12)) / (Sin(δ12) * Cos(φ2)))

If Sin(λ1 - λ1) > 0 Then
Dim θ12 As Double = θa
Dim θ21 = 2 * PI - θb
Else
Dim θ12 As Double = 2 * PI - θa
Dim θ21 As Double = θb
α1 = θ13 - θ12
α2 = θ21 - θ23
End If

Dim α3 As Double = Acos(-Cos(α1) * Cos(α2) + Sin(α1) * Sin(α2) * Cos(δ12))
Dim δ13 As Double = Atan2(Sin(δ12) * Sin(α1) * Sin(α2), Cos(α2) + Cos(α1) * Cos(α3))
φ3 = Asin(Sin(φ1) * Cos(δ13) + Cos(φ1) * Sin(δ13) * Cos(θ13)) 'p3 lat
Dim Δλ13 As Double = Atan2(Sin(θ13) * Sin(δ13) * Cos(φ1), Cos(δ13) - Sin(φ1) * Sin(φ3))
λ3 = λ1 + Δλ13 'p3 Long

' ToDegrees(φ3) : Target Lat
' ToDegrees(λ3) : Target Lon

End Sub

Return parm * PI / 180
End Function

Function ToDegrees(ByVal parm As Double)
Return parm * 180 / PI
End Function

Function KmToMiles(ByVal parm As Double)
Return parm * 0.62137119
End Function

Function KmToYrds(ByVal parm As Double)
Return parm * 1093.6133
End Function

Function KmToFt(ByVal parm As Double)
Return parm * 3280.8399
End Function

End Class
```

• Edited by Saturday, January 12, 2019 4:49 PM
Tuesday, January 8, 2019 9:20 PM

• Ken,

What language do you want to use? vb6?

Is this school work?

Describe what you want to do exactly. Do you have a picture?

Apparently the original is here.

http://edwilliams.org/avform.htm#Intersection

I am not interested in figuring it out. It does not seem like the input data you show is correct but I am not sure how the pts are defined or what the crs vals are.

```Imports System.Math
'http://edwilliams.org/avform.htm#Intersection
Public Class Form3
Dim dst12, dst13, dlon As Double
Dim lat1, lat2, lat3, ang1, ang2, ang3, lon1, lon2, lon3 As Double
lat1 = 36.13053
lat2 = 36.13024
lon1 = 105.98356
lon2 = 105.98327

Dim crs12, crs21, crs13, crs23 As Double  'pt 1, 2, 3, 4

crs12 = 91.3
crs21 = 89.3

Dim s As String

dst12 = 2 * Asin(Sqrt((Sin((lat1 - lat2) / 2)) ^ 2 +
Cos(lat1) * Cos(lat2) * Sin((lon1 - lon2) / 2) ^ 2))
If sin(lon2 - lon1) < 0 Then
crs12 = Acos((Sin(lat2) - Sin(lat1) * Cos(dst12)) / (Sin(dst12) * Cos(lat1)))
crs21 = 2 * PI - Acos((Sin(lat1) - Sin(lat2) * Cos(dst12)) / (Sin(dst12) * Cos(lat2)))
Else
crs12 = 2 * PI - Acos((Sin(lat2) - Sin(lat1) * Cos(dst12)) / (Sin(dst12) * Cos(lat1)))
crs21 = acos((sin(lat1) - sin(lat2) * cos(dst12)) / (sin(dst12) * cos(lat2)))
End If

ang1 = (crs13 - crs12 + PI) Mod (2 * PI) - PI

ang2 = (crs21 - crs23 + PI) Mod (2 * PI) - PI

If (sin(ang1) = 0 And sin(ang2) = 0) Then
s = "infinity of intersections"
ElseIf sin(ang1) * sin(ang2) < 0 Then
s = "intersection ambiguous"
Else
ang1 = abs(ang1)
ang2 = abs(ang2)
ang3 = acos(-cos(ang1) * cos(ang2) + sin(ang1) * sin(ang2) * cos(dst12))
dst13 = atan2(sin(dst12) * sin(ang1) * sin(ang2), cos(ang2) + cos(ang1) * cos(ang3))
lat3 = asin(sin(lat1) * cos(dst13) + cos(lat1) * sin(dst13) * cos(crs13))
dlon = atan2(sin(crs13) * sin(dst13) * cos(lat1), cos(dst13) - sin(lat1) * sin(lat3))
lon3 = (lon1 - dlon + PI) Mod (2 * PI) - PI
End If

'A_Target_Lat.Text = lat3            ' should be 36° 07′ 49″ N      (36.13034)
'A_Target_Lon.Text = lon3            '           105° 58′ 23″ W     (105.97278)

End Sub
End Class```

PS I may not have done the mods correctly? etc.

• Edited by Tuesday, January 8, 2019 10:42 PM
• Marked as answer by Saturday, January 12, 2019 8:03 PM
• Unmarked as answer by Saturday, January 12, 2019 8:03 PM
• Marked as answer by Saturday, January 12, 2019 8:06 PM
Tuesday, January 8, 2019 10:36 PM

### All replies

•  Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator Tuesday, January 8, 2019 9:43 PM
• Hi

If you want some help with that code, then I suggest you edit it into syntactically correct code. For example:

CHANGE THIS

```PrivateSubFindThirdGPSLocation()

Dimdst12 AsDouble

Dimlat1 AsDouble= ALatDeg        ' using : 36.13053

```

into THIS

```Private Sub FindThirdGPSLocation()

Dim dst12 As Double

Dim lat1 As Double = ALatDeg
' using : 36.13053

```

and continue through the entire code block.

Also, where are the declarations for (at least) ALatDeg, BLatDeg, ALonDeg, BLongDeg   etc etc etc .......

Regards Les, Livingston, Scotland

• Edited by Tuesday, January 8, 2019 10:19 PM
Tuesday, January 8, 2019 10:18 PM
• Ken,

What language do you want to use? vb6?

Is this school work?

Describe what you want to do exactly. Do you have a picture?

Apparently the original is here.

http://edwilliams.org/avform.htm#Intersection

I am not interested in figuring it out. It does not seem like the input data you show is correct but I am not sure how the pts are defined or what the crs vals are.

```Imports System.Math
'http://edwilliams.org/avform.htm#Intersection
Public Class Form3
Dim dst12, dst13, dlon As Double
Dim lat1, lat2, lat3, ang1, ang2, ang3, lon1, lon2, lon3 As Double
lat1 = 36.13053
lat2 = 36.13024
lon1 = 105.98356
lon2 = 105.98327

Dim crs12, crs21, crs13, crs23 As Double  'pt 1, 2, 3, 4

crs12 = 91.3
crs21 = 89.3

Dim s As String

dst12 = 2 * Asin(Sqrt((Sin((lat1 - lat2) / 2)) ^ 2 +
Cos(lat1) * Cos(lat2) * Sin((lon1 - lon2) / 2) ^ 2))
If sin(lon2 - lon1) < 0 Then
crs12 = Acos((Sin(lat2) - Sin(lat1) * Cos(dst12)) / (Sin(dst12) * Cos(lat1)))
crs21 = 2 * PI - Acos((Sin(lat1) - Sin(lat2) * Cos(dst12)) / (Sin(dst12) * Cos(lat2)))
Else
crs12 = 2 * PI - Acos((Sin(lat2) - Sin(lat1) * Cos(dst12)) / (Sin(dst12) * Cos(lat1)))
crs21 = acos((sin(lat1) - sin(lat2) * cos(dst12)) / (sin(dst12) * cos(lat2)))
End If

ang1 = (crs13 - crs12 + PI) Mod (2 * PI) - PI

ang2 = (crs21 - crs23 + PI) Mod (2 * PI) - PI

If (sin(ang1) = 0 And sin(ang2) = 0) Then
s = "infinity of intersections"
ElseIf sin(ang1) * sin(ang2) < 0 Then
s = "intersection ambiguous"
Else
ang1 = abs(ang1)
ang2 = abs(ang2)
ang3 = acos(-cos(ang1) * cos(ang2) + sin(ang1) * sin(ang2) * cos(dst12))
dst13 = atan2(sin(dst12) * sin(ang1) * sin(ang2), cos(ang2) + cos(ang1) * cos(ang3))
lat3 = asin(sin(lat1) * cos(dst13) + cos(lat1) * sin(dst13) * cos(crs13))
dlon = atan2(sin(crs13) * sin(dst13) * cos(lat1), cos(dst13) - sin(lat1) * sin(lat3))
lon3 = (lon1 - dlon + PI) Mod (2 * PI) - PI
End If

'A_Target_Lat.Text = lat3            ' should be 36° 07′ 49″ N      (36.13034)
'A_Target_Lon.Text = lon3            '           105° 58′ 23″ W     (105.97278)

End Sub
End Class```

PS I may not have done the mods correctly? etc.

• Edited by Tuesday, January 8, 2019 10:42 PM
• Marked as answer by Saturday, January 12, 2019 8:03 PM
• Unmarked as answer by Saturday, January 12, 2019 8:03 PM
• Marked as answer by Saturday, January 12, 2019 8:06 PM
Tuesday, January 8, 2019 10:36 PM
• using visual studio 2017

would like to use a program to retrieve model rockets using 2 known gps loacations and bearings from each to the rocket

trying to convert source code 'http://edwilliams.org/avform.htm'  Intersection of two paths given start points and bearings to vb

thanks

Thursday, January 10, 2019 12:18 AM
• using visual studio 2017

would like to use a program to retrieve model rockets using 2 known gps loacations and bearings from each to the rocket

trying to convert source code 'http://edwilliams.org/avform.htm'  Intersection of two paths given start points and bearings to vb

thanks

Where do your bearings come from?

What is the appox distances involved ie 1 mile  10000 miles?

What do you expect us to do for you?

Do you have questions about the code I posted?

Thursday, January 10, 2019 12:46 AM
• have solution, not sure what to do next, answers where some help, but not total solutions, have posted working code, how do I close or mark as answered?
Saturday, January 12, 2019 4:55 PM
• now have working code, thanks for the help
Saturday, January 12, 2019 5:03 PM
• Hi

If you have posted the working code, then the protocol is to mark your own post (where the code is) as Answer and to vote up on any/all other posts that assisted towards the answer.

Regards Les, Livingston, Scotland

Saturday, January 12, 2019 5:43 PM