Find the waypoint from latitude and longitude (considering the roundness of the earth).

Finded the straight line distance on the earth By the way, I played with it for a while.

from math import sin, cos, acos, asin, atan2, radians, degrees

def latlng_to_xyz(lat, lng):
    rlat, rlng = radians(lat), radians(lng)
    coslat = cos(rlat)
    return coslat*cos(rlng), coslat*sin(rlng), sin(rlat)

def xyz_to_latlng(x, y, z):
    rlat = asin(z)
    coslat = cos(rlat)
    return degrees(rlat), degrees(atan2(y/coslat, x/coslat))

def halfway_on_sphere(pos0, pos1, z=0.5):
    xyz0, xyz1 = latlng_to_xyz(*pos0), latlng_to_xyz(*pos1)

    theta = acos(sum(x * y for x, y in zip(xyz0, xyz1)))
    sin_th = sin(theta)

    v0 = sin(theta * (1-z)) / sin_th
    v1 = sin(theta * z) / sin_th

    return xyz_to_latlng(*(x * v0 + y * v1 for x, y in zip(xyz0, xyz1)))

Tokyo = 35.68, 139.77
Atlanta = 33.755, -84.39
print(halfway_on_sphere(Tokyo, Atlanta)) # (61.51, -150.67)

I found that the exact middle point between Tokyo and Atlanta was around 40km northwest of the city of Anchorage.

As you can see, the third argument of the halfway_on_sphere function can be used to calculate any internal division point. You can plot the great circle route by finding the coordinates in small steps. I think the outer equinox can probably be calculated without any problems.

Recommended Posts

Find the waypoint from latitude and longitude (considering the roundness of the earth).
Find the distance from latitude and longitude (considering the roundness of the earth).
Get the address from latitude and longitude
How to get the pixel value of the point from the satellite image by specifying the latitude and longitude
Download Geographical Survey tiles from latitude and longitude
Obtain location information (latitude and longitude) from the address. Geocode in Python ~ Geocoder and pydams ~
Give latitude and longitude point sequence data and try to identify the road from OpenStreetMap data
Find the "minimum passing score" from the "average score of examinees", "average score of successful applicants", and "magnification" of the entrance examination
Find the critical path of PERT using breadth-first search and depth-first search
Find out the age and number of winnings of prefectural governors nationwide
Capture GeneratorExit and detect the end of iteration from the generator side
Find the intersection of a circle and a straight line (sympy matrix)
Existence from the viewpoint of Python
Visualization of latitude / longitude coordinate data (assuming meteorological data) using cartopy and matplotlib
[GPS] Use pyproj to calculate distance, azimuth, and elevation from GPS latitude and longitude
Find the general terms of the Tribonacci sequence with linear algebra and Python
Find out the name of the method that called it from the method that is python
Internal / external judgment with Python: Obtain the city / town / village name from the latitude / longitude information of any point