Calculating distance and bearing

Now that you have the data, you can do some interesting things with it. For your sailboat, you'll need to use your current location and a desired new location to give your sailboat a distance and a bearing.

Longitude from your GPS device is a measure of where you are on the earth with respect to east/west. Latitude is a measure of where you are with respect to north/south. These readings are normally given in degrees (considering the fact that the globe is round, so the readings start at 0 degrees and end at 360 degrees.) Since the earth is very large, the readings also include minutes and seconds, where a single degree is divided into 60 minutes and each minute is divided into 60 seconds.

In order to calculate distance and bearing, you're going to start with longitudinal and latitudinal positions on the earth's surface in the degrees.minutes.seconds format. You'll then translate these values into a digital degree format and use the haversine formula to calculate distance and bearing.

Note

To understand the details of how the haversine formula works, refer to http://en.wikipedia.org/wiki/Haversine_formula. The website at http://www.movable-type.co.uk/scripts/latlong.html shows how the formula can be used to calculate distance and bearing.

Here is the Python code that shows the functions that convert the degree.minutes.seconds format to the digital degrees format, a function that calculates distance using the haversine formula, and another function to calculate the bearing to a new location:

Calculating distance and bearing

The following is the code that illustrates how to call these functions:

Calculating distance and bearing

The first step in the code is to set up the UART to receive the GPS data. Then you'll set the desired new location in terms of its longitude and latitude, each in the deg.min.sec format. Then the program will get the GPS data, and you can extract the latitude and longitude data from it and convert them to the digital degree format, as mentioned earlier. Then you can call both the distance and the bearing functions, and print both the distance and the bearing to the new point.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.151.141