user76704: I have a problem for about days ago and here it is :
I have an RC plane and wanna make it autonomous via GPS navigation by Arduino
I have an Arduino Mage 2560 onboard connected to a GPS Ublox-Neo-M8N (GPS module) and there is the problem
I want my RC-Plane to read it's position and go to waypoints
The Coordinates of  two waypoints  are defined before on a matrix variable like this example :
a [1] [3] =
{
    {38.884675, -116.671035, 
     245}
};

b [1] [3] =
{
    {38.725019, -116.580951, 
     1180}
};

( 1st is Latitude, 2nd is Longitude and 3rd is height)

So i want my Arduino to read it's current position from gps module's data and calculate the correct Azimuth (correct horizontal angle) and the correct pitch angle (vertical angle) to navigate my plane to the waypoints
and remember, when it reaches to the waypoint "a" with a few error (miss distance = 4 meters), it should be able to ignore navigation to the waypoint of variable "a" and then, navigate to waypoint "b"
I WAND THE EXACT COMMAND FROM ANY LIBRARY TO CALCULATE THOSE TWO ANGLE FOR NAVIGATION (azimuth direction angle and pitch angle to navigate RC-Plane from everywhere o the waypoints

user7508: The computation is not difficult. Since your drone is unlikely to travel
for thousands of kilometers, you can assume the Earth is locally flat,
and the latitude and longitude are an orthogonal coordinate system.
First, compute the vector to the next waypoint in Cartesian coordinates
(dx, dy, dz):
// Defined at global scope.
const float radians_per_degree = M_PI / 180;
const float degrees_per_radians = 180 / M_PI;
const float meters_per_degree = 1e7 / 90;

// For every reading of the GPS:
float dx = (waypoint.longitude - current.longitude) * meters_per_degree
         * cos(current.latitude * radians_per_degree);
float dy = (waypoint.latitude - current.latitude) * meters_per_degree;
float dz = waypoint.height - current.height;

Then, from this vector you can get the required angles:
float azimuth = atan2(dx, dy) * degrees_per_radians;
float pitch_angle = atan(dz/sqrt(dx*dx + dy*dy)) * degrees_per_radians;

Note that the approximation breaks down if the drone has to travel for a
distance that is a significant fraction of the distance to the closest
pole. Note also that the approximation errors are inconsequential if you
periodically update your estimate of azimuth and pitch angle: the errors
will be corrected along the way as the drone gets closer and closer to
the waypoint.
Edit: timemage posted a very interesting comment, and I would want
to further expand on the precision issue. The AVR floating point support
is indeed limited to single precision. For latitudes and longitudes in
the range shown in the question, the numerical resolution (formally, the
unit in the last place) is (3.81×10−6)° for the latitude
and (7.63×10−6)° for the longitude. This translates to about
42 cm and 66 cm respectively on the surface of the Earth. It
may be just good enough to hit the waypoint to within 4 m.
You could increase the resolution by storing the latitude and longitude
in microdegrees, as 32-bit integers. This should be easy if the GPS
always gives 6 digits after the decimal point: just ignore that
decimal point. Then, once the quantities
waypoint.longitude - current.longitude
and waypoint.latitude - current.latitude are computed, you can safely
use floating point for the rest of the computations.

76704: <p>I have a problem for about days ago and here it is :</p>
<p>I have an RC plane and wanna make it autonomous via GPS navigation by Arduino</p>
<p>I have an Arduino Mage 2560 onboard connected to a GPS Ublox-Neo-M8N (GPS module) and there is the problem</p>
<p>I want my RC-Plane to read it's position and go to waypoints</p>
<p>The Coordinates of  two waypoints  are defined before on a matrix variable like this example :</p>
<pre><code>a [1] [3] =
{
    {38.884675, -116.671035, 
     245}
};

b [1] [3] =
{
    {38.725019, -116.580951, 
     1180}
};

( 1st is Latitude, 2nd is Longitude and 3rd is height)
</code></pre>
<p>So i want my Arduino to read it's current position from gps module's data and calculate the correct Azimuth (correct horizontal angle) and the correct pitch angle (vertical angle) to navigate my plane to the waypoints</p>
<p>and remember, when it reaches to the waypoint &quot;a&quot; with a few error (miss distance = 4 meters), it should be able to ignore navigation to the waypoint of variable &quot;a&quot; and then, navigate to waypoint &quot;b&quot;</p>
<p>I WAND THE EXACT COMMAND FROM ANY LIBRARY TO CALCULATE THOSE TWO ANGLE FOR NAVIGATION (azimuth direction angle and pitch angle to navigate RC-Plane from everywhere o the waypoints</p>
 7508: <p>The computation is not difficult. Since your drone is unlikely to travel
for thousands of kilometers, you can assume the Earth is locally flat,
and the latitude and longitude are an orthogonal coordinate system.
First, compute the vector to the next waypoint in Cartesian coordinates
(dx, dy, dz):</p>
<pre class="lang-cpp prettyprint-override"><code>// Defined at global scope.
const float radians_per_degree = M_PI / 180;
const float degrees_per_radians = 180 / M_PI;
const float meters_per_degree = 1e7 / 90;

// For every reading of the GPS:
float dx = (waypoint.longitude - current.longitude) * meters_per_degree
         * cos(current.latitude * radians_per_degree);
float dy = (waypoint.latitude - current.latitude) * meters_per_degree;
float dz = waypoint.height - current.height;
</code></pre>
<p>Then, from this vector you can get the required angles:</p>
<pre class="lang-cpp prettyprint-override"><code>float azimuth = atan2(dx, dy) * degrees_per_radians;
float pitch_angle = atan(dz/sqrt(dx*dx + dy*dy)) * degrees_per_radians;
</code></pre>
<p>Note that the approximation breaks down if the drone has to travel for a
distance that is a significant fraction of the distance to the closest
pole. Note also that the approximation errors are inconsequential if you
periodically update your estimate of azimuth and pitch angle: the errors
will be corrected along the way as the drone gets closer and closer to
the waypoint.</p>
<p><strong>Edit</strong>: timemage posted a very interesting comment, and I would want
to further expand on the precision issue. The AVR floating point support
is indeed limited to single precision. For latitudes and longitudes in
the range shown in the question, the numerical resolution (formally, the
<a href="https://en.wikipedia.org/wiki/Unit_in_the_last_place" rel="nofollow noreferrer">unit in the last place</a>) is (3.81×10<sup>−6</sup>)° for the latitude
and (7.63×10<sup>−6</sup>)° for the longitude. This translates to about
42 cm and 66 cm respectively on the surface of the Earth. It
may be just good enough to hit the waypoint to within 4 m.</p>
<p>You could increase the resolution by storing the latitude and longitude
in microdegrees, as 32-bit integers. This should be easy if the GPS
always gives 6 digits after the decimal point: just ignore that
decimal point. Then, once the quantities
<code>waypoint.longitude - current.longitude</code>
and <code>waypoint.latitude - current.latitude</code> are computed, you can safely
use floating point for the rest of the computations.</p>
