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

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

Re: distance from Easter Island to Chile


From: Emanuel Berg
Subject: Re: distance from Easter Island to Chile
Date: Mon, 21 Apr 2014 04:16:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

giacomo.boffi@gmail.com writes:

> (progn (defun d2r (x) (/ (* pi x) 180)) ...

Aha, degrees-to-radians is a macro, won't play with
mapcar (?). Did some improvements (I hope) to the
interface:

(defun d2r (d) (/ (* pi d) 180))

(defun spherical-law-of-cosines (p1 p2)
  (let ((lat1 (car p1)) (lon1 (cadr p1))
        (lat2 (car p2)) (lon2 (cadr p2)))
    (acos (+ (* (sin lat1) (sin lat2))
             (* (cos lat1) (cos lat2) (cos (- lon2 lon1)))))))

(defun distance-2 (p1 p2)
  (let*((from          (car p1))
        (from-coords-r (mapcar 'd2r (cadr p1)))
        (to            (car p2))
        (to-coords-r   (mapcar 'd2r (cadr p2)))
        (dist (* 6378.1
                 (spherical-law-of-cosines from-coords-r
                                           to-coords-r)) ))
    (message (format "%s -> %s: %8.2f km" from to dist)) ))

(setq p1 '("Santiago"      (33.4500  70.6667)))
(setq p2 '("Easter Island" (27.1167 109.3667)))

(distance-2 p1 p2)

Now we just need a database of locations, then we can
really go nuts...

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


reply via email to

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