Jump to content

Recommended Posts

Posted

hi all, i wrote a program to calculate degree ,and now, i want a function to convert decimal degree to degree and minute, can anyone help me about this?

(sorry for my poor english)

  • Like 1
Posted

Its just maths 1 min = 60 secs 1 sec = 360 etc just keep taking the FIX of the decimal and moving it.

 

30d 30' 30" = 30.50833333

 

so fix = 30

rem = .508333 * 60 = 30.49999

fix = 30 mins

rem = .499999

* 60 = 29.999999 secs

  • Like 2
Posted (edited)
BIGAL said:
Its just maths 1 min = 60 secs 1 sec = 360 etc just keep taking the FIX of the decimal and moving it.

 

30d 30' 30" = 30.50833333

 

so fix = 30

rem = .508333 * 60 = 30.49999

fix = 30 mins

rem = .499999

* 60 = 29.999999 secs

 

 

another DIESEL method but not so precise , needs rounding 0.01

(defun hp:deg->dms (x) ;hanhphuc 
 (strcat (if (minusp x) "-" "")(itoa (fix (setq x (abs (atof (rtos x 2 5))))))
  (menucmd (strcat "M=$(edtime,"
		   (rtos (/ (* (+ x 1e-8) 3600.) 86400.) 2 15)
		   ",° MM' SS)" ) 
	   )
  "\"" 
  )
 )

(hp:deg->dms 30.50833333)
;"30°30'30\"" 

(hp:deg->dms -36.87)
;"-36°52'12\""

(hp:deg->dms (cvunit (atan 3 4) "radians" "degrees"))
;"36° 52' 11\"
 
test
(defun c:BD2P ( / p1 p2 sudut jarak )
  (ai_sysvar (mapcar 'cons '( "ANGBASE" "ANGDIR" "OSMODE" "DIMZIN") (list (/ pi 2.) 1 9 0)))
  (and (setq p1 (getpoint "\nPilih titik 1 : "))
       (setq p2 (getpoint p1 "\nPilih titik 2 : "))
       (setq sudut (angle p1 p2))
       (mapcar '(lambda (x) (set x (mapcar '+ '(0. 0.) (trans (eval x) 1 0)))) '(p1 p2))
       (setq jarak (distance p1 p2))
       (entmake
         (list '(0 . "MTEXT")
               '(100 . "AcDbEntity")
               '(100 . "AcDbMText")
               '(8 . "BDIST")
               (cons 1 (strcat (hp:deg->dms (distof (angtos sudut 0 16))) "\\P" (rtos jarak 2 3)))
               (cons 10 (mapcar '(lambda (a b) (/ (+ a b) 2.)) p1 p2))
               (cons 40 (* jarak 0.025))
               (cons 50 (angle p1 p2))
               '(71 . 5)
               '(72 . 5)
         )
       )
  )
  (ai_sysvar nil)
  (princ)
)

 

 
 
 
 
Edited by hanhphuc
BBCode tags removed

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...