all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: distance from Easter Island to Chile
Date: Sun, 20 Apr 2014 17:06:30 +0200	[thread overview]
Message-ID: <87sip882h5.fsf@nl106-137-194.student.uu.se> (raw)
In-Reply-To: barmar-3962B7.00444220042014@news.eternal-september.org

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	other threads:[~2014-04-20 15:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-20  0:03 distance from Easter Island to Chile Emanuel Berg
2014-04-20  3:55 ` Frank Stutzman
2014-04-20 15:14   ` Emanuel Berg
2014-04-20 22:39     ` giacomo.boffi
     [not found]     ` <mailman.19957.1398033917.10748.help-gnu-emacs@gnu.org>
2014-04-21  1:40       ` Emanuel Berg
2014-04-21  1:50         ` Emanuel Berg
2014-04-21  9:45         ` giacomo.boffi
     [not found]         ` <mailman.19981.1398073560.10748.help-gnu-emacs@gnu.org>
2014-04-21 10:35           ` Emanuel Berg
2014-04-21 10:50             ` Emanuel Berg
2014-04-23  2:49               ` Emanuel Berg
2014-04-21  2:16       ` Emanuel Berg
2014-04-20  4:44 ` Barry Margolin
2014-04-20 15:06   ` Emanuel Berg [this message]
2014-04-20  6:28 ` Eli Zaretskii
     [not found] ` <mailman.19905.1397975330.10748.help-gnu-emacs@gnu.org>
2014-04-20  7:01   ` Barry Margolin
2014-04-20  7:48     ` Eli Zaretskii
2014-04-20 10:26       ` Thorsten Jolitz
2014-04-20 11:03         ` Eli Zaretskii
2014-04-20 15:22     ` Emanuel Berg
2014-04-21  6:04       ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sip882h5.fsf@nl106-137-194.student.uu.se \
    --to=embe8573@student.uu.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.