Use of Haversines to Calculate the Position of Geographical Objects

by Evtikhov, V. G.

Evtikhov VG (2017). Use of Haversines to Calculate the Position of Geographical Objects. In Young Scientist USA, Vol. 10 (p. 3). Auburn, WA: Lulu Press.



 

Abstract. In this paper we consider methods of using haversine mathematical formulas to determine the great circle geographical distances by coordinates (latitude and longitude) obtained from API of geoinformation online services. These methods are used to calculate azimuth directions of geographical objects (facilities, buildings, streets, satellite antennas, etc.). A special software product called "SUITE FOR THE CALCULATION AND VISUALIZATION OF DISTANCES AND AZIMUTH DIRECTIONS" that is available online was implemented on the client and server sides with the help of software. The results obtained and the suite for the calculation can be used for the needs of "Smart Home" and "Smart City" projects, as well as to find the position of stars and planets in the night sky when they are observed. This paper and the suite are available as electronic resources on the Internet and Wikipedia by the following link:

http://109.73.3.247:8080/wikiweb/index.php/AZcalcmap

The software code was implemented on the server side for the purposes of international cooperation and use of this work online. It provides a possibility to choose the desired language in the drop-down menu of the graphic interface in the left vertical tool bar of the client's browser and use the development data substantially reducing linguistic and national barriers.

Keywords: geolocation, information system, spatial-coordinate data, vector representations.

 

INTRODUCTION

Problems related to training of specialists in the area of construction and development of geographic information systems as well as problems of their adoption by a wider range of users are acute in the context of rapid information and technological progress.

There are a lot of public services that allow to process coordinates of objects' position received from satellite geoposition systems using modern mobile devices (navigators, smartphones, tablets, cameras and camcorders, etc.). Information about these coordinates can be used to solve a number of domestic and socially significant issues and applied for "Smart Home" and "Smart City" projects. The importance of such issues is steadily increasing, which should be taken into account when training IT professionals. In this paper problems related to the use of software and mathematical tools for the obtaining, processing, analysis and visualization of geographic information data are discussed. The problem related to the calculation of the shortest distance between two points on the Earth's surface by their coordinates along the "great circle" is considered. This problem refers to spherical geometry and is solved with the help of a mathematical tool called "haversine" [1]. Haversines are mainly used in geodesy. The other problem was to determine the direction of the shortest distance between two points on the Earth's surface in terms of compass readings of angles that determine the azimuth of the direction. These two problems are the basis for solving of a number of practically significant issues. Such issues include consideration of natural illumination indoors within 24 hours and its changes during the year, determination of the thermal balance between the room and the environment, assessment of router capabilities that provide Wi-Fi connection in the room, problems related to the orientation of satellite antennas, as well as problems related to the availability of different mobile phone providers. These issues can also include some problems of psychologically comfortable design of living accommodations and their functional purposes. They can also include the issue of using the software described in this paper that facilitates finding and recording of observations of stars, planets, and their ecliptic in the night sky in combination with the telescope [2].

The objective of this paper was to create a web-based software product to implement possibilities of calculation of azimuthal deviations of geographical objects by the coordinates provided by geographic information systems followed by their subsequent software processing both on the client side (JavaScript) and the server side (PHP and Python) using functions for the calculation of the great circle distances between two points on a spherical surface — the haversine.

It is known that a conventional magnetic compass is strongly influenced by the surrounding magnetic fields of different nature and complex structure; therefore, as a rule, it is very problematic to follow the directions of a magnetic compass in a modern city or a building. At the same time availability of geographic information systems allows to perform such an orientation with the help of calculations and methods provided in this paper with an accuracy, acceptable for civilian needs. And the azimuthal turn of the room, building, telescope, satellite or radio antenna is of the main interest. Currently, it can most accurately be calculated using geolocation coordinates available in Google, Yandex, GIS and other search and information cartographic online services.

The following tasks were formulated to achieve this goal:

1.  To implement the algorithm for azimuthal deviations calculation on the client side using JavaScript.

2.  To implement i18n features on the server side (PHP7.0).

3.  To create a vector representation of azimuthal deviations by means of SVG followed by its addition to Wikipedia article.

4.  To introduce the vector graphics code in the article to implement the results of calculations.

The current URL to the full suite for the calculation and visualization of distances and azimuth directions is given in the Appendix.

The authors express their gratitude to senior staff scientist M.G. Evtikhov for taking part in joint discussions of the information technology, constant interest in the paper, competent advice, and carrying out of some tests.

Laws, regulations, literature and Internet resources in the area of informatics and information technology were used in this paper.

1    Main Terms and Definitions

Geolocation is the identification or estimation of the real-world geographic location of an object, such as a radar source, mobile phone, or Internet-connected computer terminal. In its simplest form geolocation can be referred to the process of determination of the location of such an object, and the location itself determined in this way. That or another positioning system is often used for geolocation purposes, and it is often more important to determine the location in a form that is easily perceived by a person (for example, a mailing address) rather than precise geographic coordinates [3]. Radio navigation techniques, for example, MLAT for greater accuracy, as well as geographic information systems are often used both for geolocation, and positioning, including geocoding.

Geocoding is the process of geographical identifiers (such as geographical coordinates expressed as latitude and longitude) assigning to map objects and data records [4]. For example, geocoding is the assignment of coordinates to records describing the address (street/house) or any other information having a geographic component. Geocoded objects can be used in geographic information systems.

A geographic information system (GIS) is an information system that provides collection, storage, processing, access, display and dissemination of spatial and coordinated data (spatial data). A GIS contains data on spatial objects in the form of their digital representations (vector, raster, quadrotomic and others) [5]. The concept of a geographic information system is also used in a narrower sense as a tool (software product) that allows to search, analyze and edit both the digital map of the locality and additional information about the objects.

It is customary to determine the latitude from the Equator towards the north. So, the latitude of points in the northern hemisphere is positive, and in the southern hemisphere — negative. The latitude of any point at the Equator is 0°, at the North pole — + 90°, at the South pole — -90° [1]. The latitude of all points at the same parallel is the same. Latitudes close to the Equator are called "low" or "tropical", and those ones close to the poles are called "high". Determination of the latitude for the purposes of maritime navigation did not present a problem — it is calculated by measuring the elevation angle of the North Star above the horizon. Determination of the longitude was a much more difficult task. Leading maritime powers announced major rewards for solving this problem.

Longitude is a coordinate in a number of spherical coordinate systems (see Figure 1).

An azimuth (from the pl. form of the Arabic noun السموت as-samt, meaning "the direction") is denoted "Az". In geodesy it is the angle between the direction to the north and the direction to any given object. The azimuth is usually measured in the direction of the visible motion of a celestial sphere (clockwise on maps).

 

Figure 1. Latitude and longitude

 

2    Haversines

 

Spherical distances were calculated by the haversine formulas [6].

 

     Spherical law of cosines use of the formula can result in errors associated with rounding in case with small distances and a small number of digits after the decimal point.

ϕ1, λ1 and ϕ2, λ2 the latitude and longitude of two points, as well as their absolute difference Δϕ, Δλ, where Δσ — the angle between               them is calculated by the spherical law of cosines (1).

 




 

 

Distance d — the arc length along the sphere of radius r and Δσ gives the result in radians (2).



 

 

     The harversine formula is used to avoid problems with small distances (3).

 

Historically, use of this function was facilitated by tables of haversines: hav(θ) = sin2(θ/2).

     The modified harversine formula is a transformed previous formula that provides more exact values of distances (4).

 




 

3   Earth Sphere

 

The shape of the Earth's surface resembles an oblate sphere (a spheroid) with a radius at the Equator of about a=6378.137 km. The distance from the center of the spheroid to the poles is b=6356.752 km. Therefore, when the shortest distances along the meridian near the Equator are calculated, the most approximate circle has a radius of b2/a=6,335.439 km, while the spheroid at the poles is more like a sphere with a radius of a2/b=6,399.594 km. As you can see, the difference is about 1%. So, calculations according to the formulas mentioned above are considered correct within 0.5%. A corresponding paper [7] is devoted to ellipsoidal geometry.

4   Preliminary Calculations

Preliminary test calculations were performed using office software spreadsheets (see Figure 2). The results obtained can be applied to most residential premises or houses located in parallel or perpendicular to the street for which calculations were performed.

 

Figure 2. Test calculations

5   Libraries of Geographic Information Systems

Geographic information systems provide constantly developing and updated innovative approaches for geodata processing. For example, Google Maps JavaScript API geometry library provides utility functions for the calculation of geometric data on the Earth's surface [8].

In Google Maps API directions are determined in degrees and are measured as clockwise deviations from the geographical north (0 degrees). The direction angle for two points can be calculated using the computeHeading() method by having transferred to it two objects LatLng with coordinates from (source point) and to (destination point). If the direction angle, the starting point and the distance (in meters) are known, destination coordinates can be calculated using the computeOffset() method. Also, if two LatLng objects and a value from 0 to 1 that indicates a part of the distance between them are know, the destination between these points can be calculated using the interpolate() method, which performs spherical linear interpolation by two points.

At the same time, access to many library functions and, in particular, the ones mentioned above, requires authentication and you have to use an API key even if you use the standard plan. Therefore, in this paper the authors implemented their own algorithms for geographic information processing on the client side using standard mathematical functions and methods of user interaction using Javascript language and CSS cascade style sheets.

6    Azimuth and Distance Calculator

 

When navigating on a sphere, orientation represents the direction angle relative to a fixed landmark — usually the true (geographical) north. There is an online calculator below that allows determining the distance and the direction azimuth determined by the coordinates of two points taken manually from any available geoinformation system, including conventional and topographic maps.

The function of coordinates reverse enabled when clicking the icon was added to the current version of the calculator (see Figure 3).


Coordinates of point A:

Coordinates of point B:

 

Calculate and show on the map!

Distance [А;В] (m):

Map autoscale:

 

Projection of the distance to the latitude at point A (m): Projection of the distance to the longitude at point A (m):

 


 

Figure 3. Online calculator

 

Interactive input of coordinates and display of calculation results on the map is carried out using Google Maps API (the link to the full suite of the azimuth calculator with interactive maps is given in the Appendix).

The results of calculations are rounded up to one hundredth of a meter (up to centimeters) and to whole degrees. The azimuth angle and the values of projection for longitude and latitude at the starting point are calculated by the coordinates of two points in addition to the distance between them. The latter ones may be of interest for the assessment of evection in latitude and longitude from the initial position (point A). For example, when flying from Moscow (Vnukovo airport) to Vladivostok (Knevichi airport) the evection in longitude will be approximately 1,376,419.63 m. It should be noted that at large distances the azimuth direction at the starting point can vary greatly from the azimuth in the end point. The developed azimuth calculator calculates the direction azimuth at the first point (A), showing the angle of deviation from the direction to the north along the arc of the great circle enclosing the Earth and passing through these two points (A, B), and as shown in the figure at large distances the direction azimuth in the starting point can be reversed at the end point (for example, Moscow-Vladivostok) (see Figure 4).

 


Figure 4. Azimuthal deviation at the starting and end points at large distances may differ significantly

 

There are different opinions about the color of the end of the compass pointing to the north. There are maps and compasses where the red color of the compass needle points to the south and vice versa. The authors used the coloring to avoid misunderstanding with Google Maps (see Figure 5).

 

 

Figure 5. Azimuth deviation of the geographic object

 

 

The figure shows the possibility of panoramic viewing of objects with georeferencing. This Google Maps functionality is used for realistic representation of addresses on the map, with the help of which users receive full information about the site they are interested in.

7    Interactive Maps

The possibility to change the location of point markers is implemented in the next interactive image of the map fragment (see Figure 6).

 

Figure 6. Interactive map

 

 

If your computer is connected to the Internet, when you press the calculator button “Calculate and show on the map!”, a satellite image of the locality with icons of points A and B is displayed in a rectangular window. Own vector icons in the form of a compass with arrows (the red one points to the north) were created to show the directions, and the icons of markers of points A and B have corresponding inscriptions and are connected by a bright green line. There is a possibility to change the location of icons by clicking (tapping) on the map or dragging for more precise positioning on the interactive image of the map fragment. Google maps API and JS scripts allowed to make it possible to automatically enter the coordinates of points in calculator registers to calculate the distance between the points and the azimuth of the direction of the line connecting them. Based on the results of calculations and depending on the location of markers of icons on the map for the specified coordinates of two points, the map is automatically centered and auto scales according to the coefficients given in Table 1.

Markers of points A and B act as location identifiers on the map. The authors developed their own marker image that is stacked on the cartographic layer. It should be noted that in this case they are usually called "badges". Markers and badges refer to Marker type objects, and they can be set in the marker constructor or by calling the setIcon() method for the marker [9]. These methods were used by the authors of this paper for the purposes of interactive communication. For example, badges receive 'drag' events and, therefore, it becomes possible to add an event listener block to show the information window that displays custom information. So, users can move badges on the map, and their coordinates will be automatically recorded in the calculator registers.

The authors used 20 scale levels available in API Google Maps provided in Table 1 in the software code to display calculation results for the purposes of map auto scaling.

 

Table 1 — Automatic scaling

No.

Scale range, m

Resolution, m/peak

Scale coef. z

Image sources

1

10

0.16

19

Aerial photography

2

20

0.31

18

 

3

50

0.63

17

DigitalGlobe/GeoEye

4

100

1.25

16

 

5

200

2.50

15

 

6

500

5.00

14

 

7

1,000

10.00

13

 

8

2,000

20.00

12

LandSat-7

9

5,000

40.00

11

 

10

10,000

80.00

10

 

11

20,000

160.00

9

 

12

20,000

307.69

8

 

13

50,000

625.00

7

 

14

100,000

1,250.00

6

 

15

200,000

2,500.00

5

 

16

500,000

5,263.16

4

 

17

1,000,000

10,526.32

3

 

18

2,000,000

21,052.63

2

 

19

5,000,000

41,666.67

1

 

20

10,000,000

83,333.33

0

 

 

8    Vector Representations of Azimuth Directions

 

Means of vector representation of azimuthal directions of geographical objects allow to get high quality images and their scientific value by introduction of frames of reference and coordinates, and also to receive aesthetically expressive forms. So, the authors implemented a vector image of a virtual compass (see Figure 7).

A JavaScript code was introduced in the scalable vector graphic image that rotates the image of the virtual compass at an angle reverse to the angle obtained as a result of calculations using the "Azimuth and Distance Calculator" with π/2 correction. This procedure allows using the image of the virtual compass displayed by mobile devices, unfolding it relative to the upper edge of- the- landscape arrangement.

 

Figure 7. Azimuth deviation of the geographic object

9   Practical Application

The obtained results can be used both for astronomical and visual observations, and to solve land navigation tasks, including tasks related to the orientation of satellite antennas and observations of the starry sky. Tasks of space arrangement in living quarters taking into account the illumination and rose of winds typical for the given locality are also of interest (see Figure 8).

 

Figure 8. Use of azimuth directions for observations

So, for the purposes of quick orientation of a residential house or another facility (object) it is enough to enter the coordinates in "Azimuth and Distance Calculator" available online or in the corresponding section of this paper or you can use the URL of the visualization and calculation suite available in the application. Then it is required to place a mobile device or a printed image of the virtual compass along a window, a wall, or another guide of a parallel (perpendicular) line passing through points A and B by which coordinates calculations were performed. The mobile device should be applied to the window or wall, so that point A is on the left, and point B — on the right. Then the virtual compass will show the direction to the north.

How does it work? For practical use, you can use the following brief instruction:

1.  Open the suite for the calculation and visualization of distances and azimuth directions: http://109.73.3.247:8080/wikiweb/index.php/AZcalcmap.

2.  Enter manually the coordinates of points A and B in the calculator registers or click on the map.

3.  Press the button "Start!" near the inscription "Calculate and show on the map!". A green line will appear between the marker badges on the map, and the virtual compass will animatedly turn to the desired position.

4.  If you print it on paper or perform the operation using you tablet, then if you take such an image to the wall parallel to the green line, so that point A is on the left relative to the sheet or tablet, and the red arrow will show the direction to the north.

It should be noted that the tablet or printed compass image can be replaced with a common sheet of paper, which should be superimposed on the screen of the monitor with the virtual compass, draw the position of the compass needle with the north mark, then this sheet can be used in any room by locating it parallel to the wall or window, so that point A is on the left, then the arrow of the compass image will point to the north.

 

CONCLUSION

In this paper the main tasks related to the use of geoinformation data for "Smart Home" and "Smart City" projects were solved. The results obtained can be used to develop a mathematical tool for information systems of various levels and complexity. The implemented web-based software product in the form of a "SUITE FOR THE CALCULATION AND VISUALIZATION OF DISTANCES AND AZIMUTHAL DIRECTIONS" was successful used for land navigation, orientation of satellite antennas and starry sky observations. The suite has a number of advantages as compared to devices based on magneto sensitive elements:

        It does not depend on magnetic interference and screening of the earth's magnetic field.

        There is no need to make a correction for the magnetic declination.

        It performs mathematical calculations and displays the results in digital form.

        Calculations visualization on online maps.

The accuracy of obtained results consists of an error of geographical coordinates taking, which depends on the method used to obtain them, and an error of calculation according to the modified haversine formula within 0.5%.

The latest version of the web suite is available by the following URL: http://109.73.3.247:8080/wikiweb/index.php/AZcalcmap.

This paper is an electronic resource and a part of Wikipedia project. It can be used when training IT specialists to the methods of software introduction in web developments both on the client and server sides, as well as the use of libraries of processing of geometric data provided by geoinformation services.

The material is adapted for the use in distance learning technologies, including training of multilingual international groups. As an electronic resource this article uses Google Translate API technology on the server side for online translation to more than 100 foreign languages, which facilitates its international use. The web-based approach to the presentation of the proposed material provides great opportunities and prospects for further elaboration of the proposed material, allows to keep it up-to-date improving and supplementing it with modern working methods and content.

Currently, the authors are working over tools that allow using any image as a map, including scanned versions of old and archival maps, surveys on the ground. These tools are of considerable interest both from the point of view of independence from geoinformation services and as tools that greatly expand the possibilities of archaeological and scientific research.

 

References

 

  1. Encyclopedia of elementary mathematics. Book four — geometry M.. Fizmatgiz, 1663, 568 pp., illustrated.
  2. Evtikhov M.V., Godunov D.I. // "Refraktorny telesmart" svoimi rukami ["Refractor telesmart" with own hands]. International scientific journal. — 2017. — No. 3, p. 1 — P. 56 — 60. (94 pp.).
  3. Geolocation (informatics) [Electronic resource]. — Access mode: https://en.wikipedia.org
  4. Geocoding [Electronic resource]. — Access mode: https://en.wikipedia.org.
  5. Geographic information system [Electronic resource]. — Access mode : http://www.gisa.ru/13058.html.
  6. Haversine formula [Electronic resource]. — Access mode: https://en.wikipedia.org/wiki/Haversine_formula.
  7. Borre, K.; Strang, WG (2012). Algorithms for Global Positioning. Welesley-Cambridge Press. ISBN 978-0-9802327-3-8. OCLC 795014501. Chapter 11, Geometry of the Ellipsoid.
  8. Geometry Library [Electronic resource]. — Access mode: https://developers.google.com/maps/documentation/javascript/geometry?hl=en.
  9. Markers [Electronic resource]. — Access mode: https://developers.google.com/maps/documentation/javascript/markers?hl=en.

 

 

Appendix

You can use the following link to access the online version of the suite for the calculation and visualisation of distances and azimuth directions: http://109.73.3.247:8080/wikiweb/index.php/AZcalcmap