RepCad Posted November 13, 2017 Posted November 13, 2017 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) 1 Quote
Lee Mac Posted November 13, 2017 Posted November 13, 2017 You could use a combination of angtof & angtos. 2 Quote
BIGAL Posted November 14, 2017 Posted November 14, 2017 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 2 Quote
hanhphuc Posted November 14, 2017 Posted November 14, 2017 (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 June 4, 2020 by hanhphuc BBCode tags removed Quote
RepCad Posted November 14, 2017 Author Posted November 14, 2017 hi guys, thanks for your reply, Quote
Recommended Posts
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.