help-gnu-emacs
[Top][All Lists]
Advanced

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

distance from Easter Island to Chile


From: Emanuel Berg
Subject: distance from Easter Island to Chile
Date: Sun, 20 Apr 2014 02:03:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

;; As you know, the Easter Bunny isn't the kind of guy
;; to go on vacation, neglecting his duty. Instead, he
;; dropped me this interesting piece of Elisp to
;; calculate the distance between Earth locations,
;; based on the "Haversine formula".
;;
;; According to the program, the Easter Island (the
;; world's most desolate place) is 4301 kilometers from
;; the capital of Chile. I Googled that selfsame
;; distance, and the result makes me think the Easter
;; Bunny pulled of a successful implementation, though
;; no one, of course, should be above criticism.
;;
;; Enjoy!

(defun sin2 (p)
  (let ((sin-p (sin p)))
    (* sin-p sin-p) ))

(defun distance (l1-r f1-r l2-r f2-r)
  (interactive)
  (let ((l1 (degrees-to-radians l1-r))
        (f1 (degrees-to-radians f1-r))
        (l2 (degrees-to-radians l2-r))
        (f2 (degrees-to-radians f2-r)) )
    (* 2 6378.1 ; Earth's radius
       (asin
        (sqrt
         (+ (sin2 (/ (- f2 f1) 2))
            (* (cos f2) (cos f1) (sin2 (/ (- l2 l1) 2))) ))))))

(distance 33.45    ; Santiago
          70.6667
          27.1167  ; Easter Island
          109.3667
          ) ; should be 3757.41 [1]

;; [1] 
http://www.mapcrow.info/Distance_between_Santiago_CI_and_Easter_Island_CI.html

-- 
underground experts united:
http://user.it.uu.se/~embe8573


reply via email to

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