• elisp program nautical - more elegant way?

    From Richard Smith@null@void.com to gnu.emacs.help on Wed Mar 15 07:47:05 2023
    From Newsgroup: gnu.emacs.help

    Hi there.
    Pardon asking on
    gnu.emacs.help
    with simple programming question.

    Program runs inside emacs, but does a nautical calculation - converts
    Google Maps' latitude and longitude in degrees-decimal to the Degrees
    Minutes and Seconds of a nautical chart - the human-usable type which
    has been around for centuries.

    Question is - is there a better way of doing my calculation?
    My skills are centred on metals and welding - hence what I have done
    which seems to work might be a risible way of doing the task.

    I looked on the web, and if I understand rightly those using an "algol
    family" eg. BASIC language do something like.

    The printed format with zero-padding - that is for the nautical
    purpose of reminding you to state the zero's on radio-messages.


    ;;; When copying-and-pasting "Google Maps" degdeci lat. and long.,
    ;;; delete the comma between the values !!!


    (defun lat-long-degdeci-to-dms (latdeci longdeci)
    (format "%s %s %s"
    (abs-degdeci-to-abs-deg-min-sec (abs latdeci) (if (minusp latdeci) 'S 'N))
    " " ;; easy jdi customisable way to separate lat. and long. output
    (abs-degdeci-to-abs-deg-min-sec (abs longdeci) (if (minusp longdeci) 'W 'E))))


    (defun abs-degdeci-to-abs-deg-min-sec (absdegdeci dirncardinal)
    "Deg-decimal to DMS format output"
    (if (minusp absdegdeci)
    "error - cannot handle negative arguments"
    (let ((decix60 (* (mod absdegdeci 1) 60)))
    (format "%03dd %02d' %04.1f'' %s" (truncate absdegdeci) (truncate decix60) (* (mod decix60 1) 60) dirncardinal))))


    ;; (lat-long-degdeci-to-dms 50.39954886056384 -3.483553379652956)
    ;; "050d 23' 58.4'' N 003d 29' 00.8'' W"
    ;;; 050 23' 58.4" N 003 29' 00.8" W
    ;;; will go back into Google Maps
    ;;; Will find you a lighthouse (maritime navigation)
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Richard Smith@null@void.com to gnu.emacs.help on Fri Mar 17 10:09:15 2023
    From Newsgroup: gnu.emacs.help

    Here's something to hopefully give a happy moment-out and deserve some comment...

    Places in the world...

    For each place / location, final line is "human-readable" but can be
    pasted back into "Google Maps" and will take you back to the place
    for which the degrees-decimal were obtained.

    ;;; Berry Head lighthouse 50.39954886056384, -3.483553379652956 (lat-long-degdeci-to-dms 50.39954886056384 -3.483553379652956)
    ;; "050d 23' 58.4'' N 003d 29' 00.8'' W"
    050 23' 58.4" N 003 29' 00.8" W

    ;; Cape Cornwall chimney 50.127233, -5.708794
    (lat-long-degdeci-to-dms 50.127233 -5.708794)
    ;; "050d 07' 38.0'' N 005d 42' 31.7'' W"
    050 07' 38.0" N 005 42' 31.7" W

    ;;; Towanroath engine house 50.305071211684954, -5.233053296845487 (lat-long-degdeci-to-dms 50.305071211684954 -5.233053296845487)
    ;; "050d 18' 18.3'' N 005d 13' 59.0'' W"
    050 18' 18.3" N 005 13' 59.0" W

    ;;; Lizard lighthouse 49.960201393209225, -5.202149785205921 (lat-long-degdeci-to-dms 49.960201393209225 -5.202149785205921)
    ;; "049d 57' 36.7'' N 005d 12' 07.7'' W"
    049 57' 36.7" N 005 12' 07.7" W

    ;;; Land's End - the sign 50.066310, -5.714791
    (lat-long-degdeci-to-dms 50.066310 -5.714791)
    ;; "050d 03' 58.7'' N 005d 42' 53.2'' W"
    050 03' 58.7" N 005 42' 53.2" W

    ;;; Clovelly harbour light 50.998692, -4.396671
    (lat-long-degdeci-to-dms 50.998692 -4.396671)
    ;; "050d 59' 55.3'' N 004d 23' 48.0'' W"
    050 59' 55.3" N 004 23' 48.0" W

    ;;; Sydney harbour bridge -33.85209267729446, 151.21082583826686 (lat-long-degdeci-to-dms -33.85209267729446 151.21082583826686)
    ;; "033d 51' 07.5'' S 151d 12' 39.0'' E"
    033 51' 07.5" S 151 12' 39.0" E

    ;; Rio de Janeiro Christ monument -22.952419527785423, -43.21046976961246 (lat-long-degdeci-to-dms -22.952419527785423 -43.21046976961246)
    ;; "022d 57' 08.7'' S 043d 12' 37.7'' W"
    022 57' 08.7" S 043 12' 37.7" W

    ;;; Yosemite Glacier Point 37.73048860656887, -119.57375861559764 (lat-long-degdeci-to-dms 37.73048860656887 -119.57375861559764)
    ;; "037d 43' 49.8'' N 119d 34' 25.5'' W"
    037 43' 49.8" N 119 34' 25.5" W

    --- Synchronet 3.21d-Linux NewsLink 1.2