1

**User Projects / Code Examples / Re: GPS "Pointer" with servos**

« **on:**February 07, 2019, 10:26:00 PM »

Not sure about the tilt part, but would the pan part correspond to the "bearing" in this distance & bearing calculation:

Algorithms for calculating distance & bearing between two points, taken from the following URL:

http://williams.best.vwh.net/avform.htm

NOTE: These formulas assume the following:

North latitudes and West longitudes are treated as positive

South latitudes and East longitudes negative

The arguments given to cos, sin, and arctan are all in RADIANS

The great circle distance d between two points, where point 1 has coordinates {lat1,lon1} and point 2 has coordinates {lat2,lon2} is given by the following:

d = acos (sin (lat1) * sin (lat2) + cos (lat1) * cos (lat2) * cos (lon1 - lon2))

The bearing, tc1, looking from point 1 to point 2, is given by the following (NOTE: This formula fails if point 1 is located at one of the two 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

Where the following applies:

asin (x) = 2 * atan (x / (1 + sqrt (1 - x * x)))

acos (x) = 2 * atan (sqrt ((1 - x) / (1 + x))) [ for x >= 0 ]

acos (x) = pi - 2 * atan (sqrt ((1 + x) / (1 - x))) [ for x < 0 ]

atan2 (y, x) = atan (y / x) [ for x > 0 ]

atan2 (y, x) = atan (y / x) + pi [ for x < 0, y >= 0 ]

atan2 (y, x) = pi / 2 [ for x = 0, y > 0 ]

atan2 (y, x) = atan (y / x) - pi [ for x < 0, y < 0 ]

atan2 (y, x) = -pi / 2 [ for x = 0, y < 0 ]

atan2 (0, 0) is undefined and should give an error.

Mark J Culross

KD5RXT

Algorithms for calculating distance & bearing between two points, taken from the following URL:

http://williams.best.vwh.net/avform.htm

NOTE: These formulas assume the following:

North latitudes and West longitudes are treated as positive

South latitudes and East longitudes negative

The arguments given to cos, sin, and arctan are all in RADIANS

The great circle distance d between two points, where point 1 has coordinates {lat1,lon1} and point 2 has coordinates {lat2,lon2} is given by the following:

d = acos (sin (lat1) * sin (lat2) + cos (lat1) * cos (lat2) * cos (lon1 - lon2))

The bearing, tc1, looking from point 1 to point 2, is given by the following (NOTE: This formula fails if point 1 is located at one of the two 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

Where the following applies:

asin (x) = 2 * atan (x / (1 + sqrt (1 - x * x)))

acos (x) = 2 * atan (sqrt ((1 - x) / (1 + x))) [ for x >= 0 ]

acos (x) = pi - 2 * atan (sqrt ((1 + x) / (1 - x))) [ for x < 0 ]

atan2 (y, x) = atan (y / x) [ for x > 0 ]

atan2 (y, x) = atan (y / x) + pi [ for x < 0, y >= 0 ]

atan2 (y, x) = pi / 2 [ for x = 0, y > 0 ]

atan2 (y, x) = atan (y / x) - pi [ for x < 0, y < 0 ]

atan2 (y, x) = -pi / 2 [ for x = 0, y < 0 ]

atan2 (0, 0) is undefined and should give an error.

Mark J Culross

KD5RXT