Home > Common Problem > body text

[Mathematical formulas and derivation] Calculate the distance between two points on the ground based on longitude and latitude

藏色散人
Release: 2020-10-22 11:39:09
forward
3607 people have browsed it

1. Assumption: The earth is a perfect sphere. The longitude and latitude coordinates of two points A and B on the ground are (Aj, Aw) and (Bj, Bw) respectively. The average radius of the earth R is 6371km.

2. Establish a three-dimensional rectangular coordinate system:

The center of the earth is the origin O, the earth's axis is the Z axis, the north pole direction is the positive direction of the Z axis, and the equatorial plane is X The plane where the axis and the Y-axis are located, on this plane, the direction from the center of the earth to the zero-degree longitude is the positive direction of the X-axis, and the positive direction of the Y-axis is determined according to the right-hand rule.

Suppose the three-dimensional coordinates of point A are (Ax, Ay, Az), and the three-dimensional coordinates of point B are (Bx, By, Bz)

3. Idea :

The plane where the three points A, B, and O intersects with the earth forms a circle with a radius R. To find the ground distance between AB is to find the length of the arc AB on the circle. It can be found by the formula that the arc length is equal to the radius multiplied by the central angle.

Since R is determined, the length of arc AB can be obtained as long as the angle θ between OA and OB is obtained. Arc AB=R*θ.
The angle θ can be obtained through the vector formula:

Vector OA*vector OB=|OA||OB|cosθ.
then

cosθ=向量OA*向量OB/|OA||OB|
     =(Ax*Bx+Ay*By+Az*Bz)/R*R
Copy after login

4. Use longitude and latitude coordinates to express the three-dimensional rectangular coordinates:

Ax=R*cosAw*cosAj
Ay=R*cosAw*sinAj
Az=R*sinAw
Bx=R*cosBw*cosBj
By=R*cosBw*sinBj
Bz=R*sinBw
Copy after login

Substitute in to get

cosθ=cosAw*cosAj*cosBw*cosBj+cosAw*sinAj*cosBw*sinBj+sinAw*sinBw
     =cosAw*cosBw(cosAj*cosBj+sinAj*sinBj)+sinAw*sinBw
     =cosAw*cosBw*cos(Aj-Bj)+sinAw*sinBw
θ=arccos[cosAw*cosBw*cos(Aj-Bj)+sinAw*sinBw]
Copy after login

5. In summary, it can be calculated based on longitude and latitude The formula for the distance between two points on the ground:

弧AB=R*arccos[cosAw*cosBw*cos(Aj-Bj)+sinAw*sinBw]
Copy after login

Description:

Everyone has done the derivation of similar formulas before. After a long time, you may forget some things, so I wrote it down. Saved for reference.

Due to the many transformations of trigonometric functions, the formula can be expressed in more than one form. As long as the premise assumptions are the same, they should be mathematically equivalent and can be deduced from each other.
When using it in actual program code, you need to pay attention to unit issues. For example, the unit of longitude and latitude obtained from the locator is degrees, and the trigonometric calculation method is likely to use radians. Another example is whether the unit of length is km or m. wait.

Recommended: "Programming Video"

The above is the detailed content of [Mathematical formulas and derivation] Calculate the distance between two points on the ground based on longitude and latitude. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template