Answered by:
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 φ1 = ToRadians(Lat1) φ2 = ToRadians(Lat2) Δφ = ToRadians(Lat2  Lat1) Δλ = ToRadians(Lon2  Lon1) 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 λ1 = ToRadians(Lon1) λ2 = ToRadians(Lon2) φ1 = ToRadians(Lat1) φ2 = ToRadians(Lat2) 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) Δφ = ToRadians(Pt2Lat  Pt1Lat) Δλ = ToRadians(Pt2Lon  Pt1Lon) φ1 = ToRadians(Pt1Lat) φ2 = ToRadians(Pt2Lat) λ1 = ToRadians(Pt1Lon) λ2 = ToRadians(Pt2Lon) 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 Function ToRadians(ByVal parm As Double) 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 kentjc Saturday, January 12, 2019 4:49 PM
Answers

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 Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load 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 tommytwotrain Tuesday, January 8, 2019 10:42 PM
 Marked as answer by kentjc Saturday, January 12, 2019 8:03 PM
 Unmarked as answer by kentjc Saturday, January 12, 2019 8:03 PM
 Marked as answer by kentjc Saturday, January 12, 2019 8:06 PM
All replies

Please edit your question and place code into a code block.
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

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 leshay Tuesday, January 8, 2019 10:19 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 Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load 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 tommytwotrain Tuesday, January 8, 2019 10:42 PM
 Marked as answer by kentjc Saturday, January 12, 2019 8:03 PM
 Unmarked as answer by kentjc Saturday, January 12, 2019 8:03 PM
 Marked as answer by kentjc Saturday, January 12, 2019 8:06 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

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
Lets see your data.
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?


