Approximation of distance between locations on earth given by latitude and longitude Jan Behrens 2012-12-31 In this paper we shall provide a method to approximate distances between two points on earth given by latitude and longitude. The motivation behind this approximation is the efficient mass-calculation of distances between a reference point and other nearby points in a huge database, while saving the expenses of trigonometric calculations for each point in the database. The approximation is done by approximating the squared distance with a 2nd order Taylor-polynomial. Finally we will present a method to calculate latitude and longitude boundaries for a given center point and radius, in order to allow quick lookup of entries using a 2-dimensional database index. We model the earth using a reference ellipsoid as defined by the formulas below, where a is the semi-major and b is the semi-minor axis of a reference ellipsoid e.g. WGS-84) in meter. X = N φ cosφ cosλ Y = N φ cosφ sinλ Z = N φ 1 ǫ 2 ) sinφ a2 b ǫ = 2 a a N φ = 1 ǫ2 sin 2 φ 1
The distance d of two points X,Y,Z) and X 0,Y 0,Z 0 ) in 3-dimensional space is given by: d 2 = X X 0 ) 2 +Y Y 0 ) 2 +Z Z 0 ) 2 = N φ cosφ cosλ N φ0 cosφ 0 cosλ 0 ) 2 +N φ cosφ sinλ N φ0 cosφ 0 sinλ 0 ) 2 +N φ 1 ǫ 2 ) sinφ N φ0 1 ǫ 2 ) sinφ 0 ) 2 Note that the path on the surface of the ellipsoid is distinct from d. For our approximation of d 2 with a 2nd order Taylor-polynomial this discrepancy has no negative impact, as it does not affect any of its coefficients not proven here). The Taylor-polynomial d 2 is given by: d 2 d 2 = 2 i=0 2 i φ λj d 2 ) φ=φ0,λ=λ 0 φ φ 0 ) i λ λ 0 ) j i!j! }{{} =:t ij j=0 Using a computer algrabra software, we can calcuate t ij and get the following results: t 00 = 0 t 10 = 0 = a 2 1 ǫ 2 ) 2 1 ǫ2 sin 2 φ 0 ) 3 t 01 = 0 t 11 = 0 t 21 = 0 t 02 = a 2 1 sin 2 φ 0 1 ǫ 2 sin 2 φ 0 t 12 = a 2 1 ǫ2 )sinφ 0 cosφ 0 1 ǫ2 sin 2 φ 0 ) 2 t 22 = a 2 1 ǫ2 ) 1 sin 2 φ 0 ) 1 2 +ǫ2 sin 2 φ 0 ) 1 ǫ2 sin 2 φ 0 ) 3 2
With t 00 = t 10 = t 01 = t 11 = t 21 = 0 we can re-write d 2 as: d 2 = φ φ 0 ) 2 +t 22 φ φ 0 ) 2 +t 12 φ φ 0 )+t 02 )λ λ 0 ) 2 = φ φ 0 ) 2 t22 + φ φ 0 ) 2 + t 12 φ φ 0 )+ t ] 02 )λ λ 0 ) 2 t 20 = φ φ 0 ) 2 t22 + φ 2 2 t 22 φφ 0 + t 22 φ 2 0 + t 12 φ t 12 φ 0 + t ] 02 )λ λ 0 ) 2 t 20 = φ φ 0 ) 2 t22 + φ 2 + t 12 2 t 22 φ 0 )φ+ t 22 φ 2 0 t 12 φ 0 + t ] 02 )λ λ 0 ) 2 t 20 = t }{{} 20 φ φ 0) 2 + =: t 22 }{{} =:c 2 φ 2 + t 12 2t 22 φ 0 } {{ } =:c 1 φ+ t 22φ 2 0 t 12 φ 0 +t 02 } {{ } =:c 0 λ λ 0) 2 Defining 4 constants := c 2 := t 22 c 1 := t 12 2t 22 φ 0 c 0 := t 22φ 2 0 t 12 φ 0 +t 02 we can further simplify d 2 to: d 2 d 2 = φ φ0 ) 2 +c 2 φ 2 +c 1 φ+c 0 )λ λ 0 ) 2] = φ φ0 ) 2 +c 2 φ+c 1 )φ+c 0 )λ λ 0 ) 2] 3
Given a minimum r) and maximum R) search radius, we can filter database entries using the following formula: r 2 φ φ 0 ) 2 +c 2 φ+c 1 )φ+c 0 )λ λ 0 ) 2 < R2 If latitudes and longitudes are not given as radians but as degrees, we can use alternative coefficients: π c 3 = 180 π c 2 = 180 c 1 = π 180 c 1 c 0 = c 0 ) 2c3 ) 2c2 In order to get the latitude boundaries φ b = φ 0 ± φ b for a given center pointφ 0, λ 0 )andmaximumsearchradiusr), weusethesimplifiedequation for d 2 and set d 2 = R 2, φ = φ b and λ = λ 0 : d 2 = φ φ0 ) 2 +c 2 φ 2 +c 1 φ+c 0 )λ λ 0 ) 2] R 2 = φ b φ 0 ) 2 + c 2 φ 2 b +c 1 φ b +c 0 )λ 0 λ 0 ) 2 R 2 = φ b φ 0 ) 2 φ b φ 0 ) 2 = R2 φ b = φ b φ 0 = R 2 4
The longitude boundaries λ b = λ 0 ± λ b are calculated by setting d 2 = R 2, λ = λ b and φ to a critical value φ c, which maximizes λ b λ 0 : d 2 = φ φ0 ) 2 +c 2 φ 2 +c 1 φ+c 0 )λ λ 0 ) 2] R 2 = φc φ 0 ) 2 +c 2 φ 2 c +c 1 φ c +c 0 )λ b λ 0 ) 2] φ c φ 0 ) 2 +c 2 φ 2 c +c 1 φ c +c 0 )λ b λ 0 ) 2 = R2 c 2 φ 2 c +c 1 φ c +c 0 )λ b λ 0 ) 2 = R2 φ c φ 0 ) 2 λ b λ 0 ) 2 = λ b = λ b λ 0 = R 2 φ c φ 0 ) 2 c 2 φ 2 c +c 1 φ c +c 0 R 2 φ c φ 0 ) 2 c 2 φ 2 c +c 1 φ c +c 0 φ c canbedeterminedbysetting λ b λ 0 ) 2 ) φ c = 0. Usingacomputeralgebra software, we get two results, of which only the following result leads to φ c π 2 ;+π] and real λ 2 b: φ c = c 2 φ 2 0 R2 ) c 0 + c 2 2 φ 4 0 + 2c 1 c 2 φ 3 0 + c 2 R 1+2c 0 c 2 2 )c 2 ) φ 2 0 R + 2c 0 c 2 2 )c 1 φ ) 0 2+2c0 + c 2 R 2 2 c 2 c 2 1) R2 +c 2 0 2c 2 φ 0 +c 1 The above formula only holds for cases where φ 0 0 and the north or south pole is not included within the search radius. If φ 0 = 0, then φ c = 0. It is recommended to limit φ c to an absolute value φ limit ), which is the maximum possible absolute value of φ in practice, e.g. 84 = 7 π. When 15 φ c > φ limit, then φ limit should be used instead of φ c to calculate λ b. When φ c < φ limit, then φ limit should be used respectivly. When φ c / R, because a pole is included within the search radius, then φ limit can be used for cases where φ 0 > 0, and φ limit can be used for cases where φ 0 < 0. 5
In addition to the outer boundaries φ b = φ 0 ± φ b and λ b = λ 0 ± λ b for the maximum radius R, it is possible to define inner boundaries φ i,λ i ) for the minimum radius r. There are infinite possible solutions, we pick one by chosing λ i as follows: r 2 c λ i = λ i λ 0 = 3 2 c 2 φ 2 0 +c 1 φ 0 +c 0 ) Our choice of λ i is optimal for φ 0 = 0 and r 0 not proven here). Having chosen λ i, we can calculate φ i by using the simplified equation for d 2 and setting d 2 = r 2, φ = φ i and λ = λ i : d 2 = φ φ0 ) 2 +c 2 φ 2 +c 1 φ+c 0 )λ λ 0 ) 2] r 2 = φi φ 0 ) 2 +c 2 φ 2 i +c 1 φ i +c 0 )λ i λ 0 ) 2] r 2 = φi φ 0 ) 2 +c 2 φ 2 i +c 1 φ i +c 0 ) λ i ) 2] r2 = φ i φ 0 ) 2 +c 2 φ 2 i +c 1 φ i +c 0 ) λ i ) 2 r2 = φ 2 i 2φ i φ 0 +φ 2 0 +c 2 λ i ) 2 φ 2 i +c 1 λ i ) 2 φ i +c 0 λ i ) 2 c 2 λ i ) 2 +1)φ 2 i +c 1 λ i ) 2 2φ 0 )φ i +c 0 λ i ) 2 +φ 2 0 r2 = 0 1 φ 0 1 4 c 2 1 λ i ) 2 c2 1 c 0 c 2 ) λ i ) 4 r ± +c 2 2 c 2 φ 2 0 +c 1 φ 0 +c 0 )) λ i ) 2 + r2 c φ i = 3 c 2 λ i ) 2 +1 φ i = φ 0 1 2 c 1 λ i ) 2 ± 1 4 c2 1 c 0 c 2 ) λ i ) 4 r +c 2 2 λ i ) 2 + 1 r 2 2 c 2 λ i ) 2 +1 Note that the two solutions of φ i are normally not symmetrical to φ 0. 6