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: Sun, 20 Apr 2014 17:06:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Barry Margolin <barmar@alum.mit.edu> writes:

>> (defun distance (l1-r f1-r l2-r f2-r) (interactive)
>
> If you declare this interactive, you need to provide
> a specification string for the arguments, so that it
> can prompt for them.

Right, I forgot about that. It is not used
interactively in the demo, and it is not really suited
for that, because it is a pain (and error-prone) to
enter those digits in the minibuffer - better to put
them in a form and evaluate it (I think `C-x C-e' or
`C-M-x' are the standard keybindings).

Then the digits are "persistent" as well and you can
add more locations.

If you were to do that it would perhaps make sense to
redo the interface slightly to make it accept to
*lists* referring to locations, and tagged with metadata
to make the output more "human", as in:

("Easter Island" (and more ...) 27.1167 109.3667)

But a simple interactive version could look like this:

(defun distance (l1-d f1-d l2-d f2-d)
  (interactive "nLatitude 1: \nnLongitude 1: \nnLatitude 2: \nnLongitude 2: ")
  (let ((l1 (degrees-to-radians l1-d))
        (f1 (degrees-to-radians f1-d))
        (l2 (degrees-to-radians l2-d))
        (f2 (degrees-to-radians f2-d)) )
    (message "%s"
             (* 2 6378.1 ; Earth's radius
                (asin
                 (sqrt
                  (+ (sin2 (/ (- f2 f1) 2))
                     (* (cos f2) (cos f1) (sin2 (/ (- l2 l1) 2))) )))))))

> And your argument names are not very helpful. They're
> apparently latitude and longitude, so what does "f"
> mean?

I got the f's and l's from the Haversine formula
itself, as it was presented on Wikipedia, though in
that formula, they were actually the Greek letters
phi and lambda, respectively.

I agree that "latitude" and "longitude" are better
names, but then the math code would get "chatty", and
it would be difficult to see the formula behind it. I
don't know if the scientific community has some
short-forms (preferable single-lettered) for those
quantities? (It would be a no-brainer if they didn't
both start with "l"s...)

> And what is the "-r" suffix on all of them?

Right, that should be "-d" (for degrees), as that's
what you input - it gets converted to radians in the
`let' form.

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


reply via email to

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