XAxis = cos(radians(Latitude)) * cos(radians(Longitude))
&& let's consider cos(radians(Latitude)) && convert to radians cos( (Latitude * (PI/180) )) && subsitute PI cos( (Latitude * (4*((4*atn(1/5))-(atn(1/239)))/180) ))I have the distance between New York and Brussels
&& 6378.137 is the radius of the earth in km *___________________________________________________________________________ function do_it() create cursor Coordinates ; ( co_pk I, ; co_city c(40), ; co_latitude b(16), ; co_longitude b(16), ; co_x b(16), ; co_y b(16), ; co_z b(16) ; ) insert into Coordinates ; ( co_pk, co_city, co_latitude, co_longitude) ; values ; (1, 'New York', dtor(40.0 + 45/60 + 6/3600), -dtor(73.0 + 59/60 + 39/3600) ) insert into Coordinates ; ( co_pk, co_city, co_latitude, co_longitude) ; values ; (2, 'Brussels', dtor(50.00 + 50/60 + 0/3600), dtor(4.0 + 20/60 + 0/3600) ) update Coordinates ; set co_x = cos(co_latitude) * cos(co_longitude), ; co_y = cos(co_latitude) * sin(co_longitude), ; co_z = sin(co_latitude) select T1.co_pk, ; T1.co_city, ; T2.co_pk, ; T2.co_city, ; Distance(T1.co_latitude, T1.co_longitude, T2.co_latitude, T2.co_longitude) as Distance, ; 6378.137 * acos( T1.co_x * T2.co_x + T1.co_y * T2.co_y + T1.co_z * T2.co_z) as Distance2 ; from Coordinates T1 ; join Coordinates T2 on (T1.co_pk < T2.co_pk) ; into cursor tmp && =brow() endfunc *___________________________________________________________________________ function Distance(lat1, lon1, lat2, lon2) local theta, dist theta = m.lon1 - m.lon2 dist = sin(m.lat1) * sin(m.lat2) + cos(m.lat1) * cos(m.lat2) * cos(m.theta) dist = acos(m.dist) dist = rtod(m.dist) dist = m.dist * 60 * 1.1515 * 1.609344 return m.dist endfunc *___________________________________________________________________________