Calculation of distance between two points on the ground based on latitude and longitude-mathematical formula and Derivation

Source: Internet
Author: User

1. Assume that the Earth is a positive sphere. The longitude and latitude coordinates of point A and point B on the ground are (Aj, Aw) and (Bj, Bw) respectively, and the mean value of the earth's radius R is 6371 km.

2. Create a three-dimensional Cartesian coordinate system:
The earth's ball center is the origin O, the ground axis is the Z axis, the Arctic direction is the positive direction of the Z axis, the Equator plane is the X axis and Y axis of the plane, on the plane, the direction from the center to the zero longitude line is the positive direction of the X axis, and the positive direction of the Y axis is determined according to the right hand direction.
Set the three-dimensional coordinates of point A to (Ax, Ay, Az). The three-dimensional coordinates of point B are (Bx, By, Bz)

3. Ideas:
The plane at which the points A, B, and O are located forms A circle with A radius of R at the intersection of the earth. The distance between the ground and the AB is the length of the arc AB on the circle. The formula can be obtained by multiplying the arc length by the radius by the center angle.
Since R is determined, the arc AB length can be obtained as long as the angle θ between OA and OB is obtained. Arc AB = R * θ.
Angle θ can be obtained through the vector formula: vector OA * vector OB = | OA | OB | cos θ.
Then
Cos θ = vector OA * vector OB/| OA | OB |
= (Ax * Bx + Ay * By + Az * Bz)/R * R

4. Use latitude and longitude coordinates to represent three-dimensional Cartesian coordinates:
Ax = R * cosAw * cosAj
Ay = R * cosAw * sinAj
Az = R * sinAw

Bx = R * cosBw * cosBj
By = R * cosBw * sinBj
Bz = R * sinBw

Substitution
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]

5. Calculate the distance between two points on the ground based on the longitude and latitude:
Arc AB = R * arccos [cosAw * cosBw * cos (Aj-Bj) + sinAw * sinBw]

Note: similar formulas have been deduced before, and some things may be forgotten after a long time, so I wrote them down for reference.
Due to the multiple ends of trigonometric function transformation, this formula has more than one representation. As long as the premise assumption is the same, it should be equivalent in mathematics and can be deduced from each other.
When using the actual program code, pay attention to the unit problem. For example, the unit of latitude and longitude obtained from the positioner is degree, and the unit of triangle calculation is probably radian, for example, the unit of length is km or m.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.