JMW
Aspiring Addon Developer
Can anyone help with this for an autopilot?
Computing a heading to a base from current position.
Searching drew a blank except for this deep examination.
And this:
but can't get it to work.
There must be a simple formula, no?:thumbup:
Computing a heading to a base from current position.
Searching drew a blank except for this deep examination.
And this:
Code:
Course between points
We obtain the initial course, tc1, (at point 1) from point 1 to point 2 by the following. The formula fails if the initial point is a pole. We can special case this with:
IF (cos(lat1) < EPS) // EPS a small number ~ machine precision
IF (lat1 > 0)
tc1= pi // starting from N pole
ELSE
tc1= 2*pi // starting from S pole
ENDIF
ENDIF
For starting points other than the poles:
IF sin(lon2-lon1)<0
tc1=acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
ELSE
tc1=2*pi-acos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
ENDIF
An alternative formula, not requiring the pre-computation of d, the distance between the points, is:
tc1=mod(atan2(sin(lon1-lon2)*cos(lat2),
cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon1-lon2)), 2*pi)
There must be a simple formula, no?:thumbup:
