[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: distance from Easter Island to Chile

From: giacomo . boffi
Subject: Re: distance from Easter Island to Chile
Date: Mon, 21 Apr 2014 11:45:29 +0200
User-agent: Gnus/5.101 (Gnus v5.10.10) XEmacs/21.5-b34 (linux)

Emanuel Berg <address@hidden> writes:

> address@hidden writes:
>>> I get an answer of 4301.199
>> me too
> Provided the implementation is correct that's what you get with the
> Haversine method.

(defun d2r (x) 
  "degrees-to-radians is a macro, won't work with mapcar..."
  (/ (* x pi) 180))

; wolfram's alpha says
(setq average-earth-radius 6367.4447)

; there are sources that report different locations
; for Santiago and Easter Island
(setq santiago (mapcar 'd2r '(33.4500  70.6667)))
(setq easter_i (mapcar 'd2r '(27.1167 109.3667)))

(defun haversines (p1 p2)
  "Returns a list with sin^2(Delta_Lat/2) and sin^2(Delta_Lon/2)."; 
  (flet ((d2 (x) (/ x 2))
         (p2 (x) (* x x)))
    (mapcar 'p2 (mapcar 'sin (mapcar 'd2 (mapcar* '- p1 p2))))))

(defun central-angle (p1 p2)
  "Returns the central angle between two locations on a sphere,
using the haversine formula. "
  (let* ( (hs (haversines p1 p2))
          (hs-lat (car  hs))
          (hs-lon (cadr hs))
          (cos-lat1 (cos (car p1)))
          (cos-lat2 (cos (car p2)))
    (* 2 (asin (sqrt (+ hs-lat (* cos-lat1 cos-lat2 hs-lon)))))))

(insert (format "\n%f" (* 6378.1 
                        (central-angle santiago easter_i))))

(insert (format "\n%f" (* average-earth-radius 
                        (central-angle santiago easter_i))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]