I have a list of latitudes and longitudes for the US/Canadian border and need to determine if a particular lat/long pair (within Canada) is within 225 miles of the US border. Obviously this is a fairly complicated line and the 225 miles could be in almost any direction from the point being checked.
This needs to be a generic solution because I need to run it many times over a large number of points.
I have considered two solutions, but have been unable to make either of them work. Help with either would be greatly appreciated!
1. Come up with a "new border" which includes all of the area within 225 miles of the border and then see if the point is inside this line. I know that the code would have to generate a lot of arcs, see where they intersect, and just use the outline of this area to define the new line.
2. Calculate a 225 ring around the point and see if it intersects the polyline defining the border at any point. I'm thinking that this would be easier, but am not sure how to start.
Attached is my excel file containing the lat/long's for the border in both degrees and radians.
Thanks in advance!
'This formula will probably come in handy (whether used to calculate points for a circle, or the expanded border):
'Destination point given distance and bearing from start point:
Public Function CalculateDistance()
'd is distance traveled in radians - 225 miles in this case
d = 225 / 3963.1676
'lat1 = Latitude of the starting position
lat1 = 0.706009923115762
'lon1 = Longitude of the starting position
lon1 = 1.14667647042346
'brg is the bearing from lat1/lon1 in radians
brng = 180 * Pi / 180
lat2 = ArcSin(Sin(lat1) * Cos(d) + Cos(lat1) * Sin(d) * Cos(brng))
lon2 = lon1 + Application.WorksheetFunction.Atan2(Cos(d) - Sin(lat1) * Sin(lat2), Sin(brng) * Sin(d) * Cos(lat1))
Function ArcSin(X As Double) As Double
ArcSin = Atn(X / Sqr(-X * X + 1))