From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: distance from Easter Island to Chile Date: Sun, 20 Apr 2014 17:06:30 +0200 Organization: Aioe.org NNTP Server Message-ID: <87sip882h5.fsf@nl106-137-194.student.uu.se> References: <87mwfguasr.fsf@nl106-137-194.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1398006624 16525 80.91.229.3 (20 Apr 2014 15:10:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 20 Apr 2014 15:10:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 20 17:10:19 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WbtNr-0006eE-1Z for geh-help-gnu-emacs@m.gmane.org; Sun, 20 Apr 2014 17:10:19 +0200 Original-Received: from localhost ([::1]:45828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WbtNq-0003iD-Ar for geh-help-gnu-emacs@m.gmane.org; Sun, 20 Apr 2014 11:10:18 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 66 Original-NNTP-Posting-Host: VVbyYd/iFZoeWNmD9i++cQ.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:uCCi5sj+IB+QpicEKzuBDeDYQXk= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:205000 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97265 Archived-At: Barry Margolin 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