The formula for the smoothing law of cosines

I am trying to calculate the longitude of a point from another longitude. They have the same latitude, and the distance between them is known. I am trying to use the sperical law of cosines formula .

# 'lat' short for 'latitude', 'lng' short for 'longitude'.
# EARTH_RADIUS = 6371000.0, unit is meter.
#
distance = Math.acos( Math.sin(lat1)*Math.sin(lat2) + 
           Math.cos(lat1)*Math.cos(lat2) * 
           Math.cos(lng2-lng1)) * EARTH_RADIUS

If the two point latitudes are equal (lat1 == lat2), I can calculate lng2 from lng1 with distance. Therefore, I am reasoning the formula from the formula sperical law of cosines

# lat1 == lat2 == lat
# 'distance' and 'lng' are known 
lng2 = Math.acos((Math.cos(distance/EARTH_RADIUS) - Math.sin(lat)*Math.sin(lat))/(Math.cos(lat)*Math.cos(lat))) + lng

This formula works very well, except in some situations.

how

lat_degrees =  -89.8345981836319  
lng_degrees = 96.42309331893921
lat = lat1 = lat2 = (lat_degrees * Math::PI)/180 # -1.567909520510494
lng = (lng_degrees * Math::PI)/180  # 1.682900453373236 
distance = 67544.06725769254

This will result in an error.

Math::DomainError: Numerical argument is out of domain - "acos"

Because the value in Math.acos (value) is -2.5100189069914602, which is less than -1. I have no idea about this. Is a derived formal error incorrect?

+3
source share
2 answers

. , , , (!!) , , .

+4

:

if lat1 == lat2 and lng1 == lng2
  return 0
end
0

All Articles