Author Topic: (code) dd.mmss -> dd  (Read 3342 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
(code) dd.mmss -> dd
« on: April 24, 2004, 12:45:36 PM »
All comments, questions welcome.   :roll:
Code: [Select]

(defun dms->deg (num / d m s)
  (setq d (fix num)
        m (fix (* (- num (fix num)) 100))
        s (* (rem (* (- num (fix num)) 100) 1.0) 100)
        )
  (+ d (/ (+ (/ s 60) m) 60))
  )
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
(code) dd.mmss -> dd
« Reply #1 on: April 25, 2004, 10:26:10 AM »
There is probably a more elegant of doing this but.
Code: [Select]

(defun deg->dms (num)
  (setq d (fix num)
        m (fix (* (- num (fix num)) 60))
        s (atoi (rtos (* (rem (* (- num (fix num)) 60) 1) 60) 2 0))
        )

  (if (< m 10)
    (setq m (strcat "0" (itoa m)))
    (setq m (itoa m))
    )
 
  (if (< s 10)
    (setq s (strcat "0" (itoa s)))
    (setq s (itoa s))
    )

  (atof (strcat (itoa d) "." m s))
  )
TheSwamp.org  (serving the CAD community since 2003)

DEVITG

  • Bull Frog
  • Posts: 479
"all trail goes to Rome"
« Reply #2 on: April 25, 2004, 11:50:06 AM »
could it be done just with ANGTOS  and ANGTOF  back and forth

Guess you have  

Code: [Select]
(setq ang "180d0'25\"")

(Setq angr (angtof ang))

(setq ang-deg (angtos angr 0 5))


Given the ang in d m s

you get ang in d.xxxxx




Code: [Select]
(SETQ ang-dec 60.2556)
(setq $ang-dec (rtos ang-dec))
(setq angrr (angtof $ang-dec))
(setq ang-dms (angtos angrr 1 4))


And given the ang as d.xxx  you get D M S
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
(code) dd.mmss -> dd
« Reply #3 on: April 25, 2004, 12:28:52 PM »
Good idea DEVITG
TheSwamp.org  (serving the CAD community since 2003)