Click here to Skip to main content
13,740,862 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a code set that calculates flightlines, starting with a lat/lon, initial direction, turn direction, track length,track width And line count.

All variables are defined as decimal

Using 135 degrees and 315 degrees, 100 mile track, I get 2 different results. The southeast course points are 100.5671 miles apart, and the Northwest points are 99.23002 miles apart. This skews my flight lines start and ends, but the lines are parallel

In testing with 90/270 headings, with longer lines, the lat/lon pairs seem to cause a 1.1 degree variance in headings, but calculate to the same path lengths and longitudes, but differing longitudes so the flight lines are not parallel

Here are the formulas

Call GetNextLineStart(EndLatRadians, EndLonRadians, TrackWidthKM, connectingCourseRadians)
LineStartLatDD = rad2deg(EndLatRadians)
LineStartLonDD = rad2deg(EndLonRadians)
LineCourseRadians = deg2rad(LineCourseDD)Call GetNextLineStart(EndLatRadians, EndLonRadians, TrackLengthKM, LineCourseRadians)
LineEndLatDD = rad2deg(EndLatRadians)
LineEndLonDD = rad2deg(EndLonRadians)


Sub GetNextLineStart(Lat1, Lon1, Dist, Course)
' lat lon in radians, dist in km, course in radians
Call GetNewlat(Lat1, Lon1, Dist, Course)
Call GetNewlon(Lat1, Lon1, Dist, Course)
NewEndLatDD = RadToDeg(EndLatRadians)
NewEndLonDD = RadToDeg(EndLonRadians)

End Sub

And the real meat

Sub GetNewlat(Lat1, Lon1, Dist, Bearing)
Dim R As Decimal = 6378.1
EndLatRadians = Math.Asin(Math.Sin(Lat1) * Math.Cos(Dist / R) + Math.Cos(Lat1) * Math.Sin(Dist / R) * Math.Cos(Bearing))
End Sub
Sub GetNewlon(Lat1, Lon1, Dist, Bearing)
Dim R As Decimal = 6378.1
EndLonRadians = Lon1 + Math.Atan2(Math.Sin(Bearing) * Math.Sin(Dist / R) * Math.Cos(Lat1), Math.Cos(Dist / R) - Math.Sin(Lat1) * Math.Sin(Lat1))
End Sub

What I have tried:

I changed the variables to decimal- no change,
Posted 19-Oct-17 10:47am
Updated 19-Oct-17 12:23pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You appear to be using a spherical model, which is OK for low accuracy calculations.
I suspect the fundamental reason you get funny results is that you are calculating the implicit longitude scaling factor (cosine of latitude) at one end of your line.
There are all sorts of other counter-intuitive things about lat/lon calculations. For example, in general the bearing from A to B is in general, NOT 180 degrees different to the bearing from B to A.
And things get even more complicated when you use a more realistic ellipsoidal model (like GPS uses). If you want to see how it really words, start somewhere like ICSM - GDA Technical Manuals[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 19 Oct 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100