ignarous Posted August 21, 2017 Posted August 21, 2017 Function that converts radians to degrees, minutes and seconds, as numbers to operate with them (not text) Thanks Quote
hanhphuc Posted August 21, 2017 Posted August 21, 2017 Function that converts radians to degrees, minutes and seconds, as numbers to operate with them (not text) Thanks (defun rtod( x) ;radians to degrees (/ (x 180.0) pi) ) (defun dtor(x) ;degress to radians (* (/ x 180.0) pi) ) (setq deg 90.) (setq rad (dtor deg)) ;1.5708 (cvunit rad "radians" "degrees") ;90. not sure what you mean (not text)? (angof 1.5708 1 4) ? Quote
ignarous Posted August 21, 2017 Author Posted August 21, 2017 Thank you for responding so quickly. Please allow the function not only to convert RAD to DEC, but to DMS (degrees, minutes and seconds) . Example : Question = 0.5811849 (RAD) Answer 1 = 33.2994444 (DEC) Answer 2 = 33 ° 17' 58 "(DMS) Additionally, I would appreciate if possible, that data be sent by reference (not by value) to the function It was mentioned that they are not texts, because I have to perform operations with the DMS angle returned by the function THANK YOU Quote
Lee Mac Posted August 21, 2017 Posted August 21, 2017 _$ (angtos 0.5811849 1 4) "33d17'58\"" _$ (angtos 0.5811849 0 4) "33.2994" Quote
BIGAL Posted August 22, 2017 Posted August 22, 2017 (edited) Or this (setq ang 2.40542) (setq ang (/ (* ang 180.0) pi)) ; convert to decimal degrees (setq deg (fix ang)) (setq mins (* 60.0 (- ang (fix ang)))) (setq sec (* 60.0 (- mins (fix mins)))) (setq mins (fix mins)) (alert (strcat "Degs = " (rtos deg 2 0) "\nMins = " (rtos mins 2 0) "\nSecs = " (rtos sec 2 0))) Edited August 25, 2017 by BIGAL Quote
hanhphuc Posted August 22, 2017 Posted August 22, 2017 (edited) not sure what you mean (not text)? (angof 1.5708 1 4) ? Oops.. just notices typos should be ([color="blue"]angtos[/color] 1.5708 1 4) angtos accepts 3 argument angtof only accepts single argument which converts angle (string) to radians Thanks Lee's input for OP Or this (setq [color="blue"]min[/color] ... protected symbol Answer 2 = 33 ° 17' 58 "(DMS) Additionally, I would appreciate if possible, that data be sent by reference (not by value) to the function It was mentioned that they are not texts, because I have to perform operations with the DMS angle returned by the function THANK YOU The DMS value converted by angtos is a string (you mean Text?), which you can't perform arithmetic calculations (+ - * / etc..), argument should be numbers unless (angtos (+ ang1 ang2) 1 4) ;where ang1 ang2 must be numbers (radians) If reference means argument? from library but maybe not you want due to the result is "Text" (string) ; limitation prec <= 4 (defun _dmmss (ang prec / $ l n s) ;hanhphuc (setq $ (angtos ang 1 prec) l (mapcar ''((x) (vl-string-search x $)) '("\"" "'" "d"))) (if (and (cadr l) (setq n (apply '- (cdr l)) l (if (car l)(list (- (car l) (cadr l)) n) n) s (strcat (if (minusp ang)"-""") (vl-string-translate "d-" "°0"(cadr (eval (cons 'cond (mapcar '(lambda (i j)(vl-list* (equal l i) (mapcar 'cons '(setq mapcar) (list '(s $) (vl-list* ' ' ' ((a b) (setq s (vl-string-subst (strcat a b) a s))) (mapcar 'cons '(list list) (list '("'" "d") (mapcar ''((x)(strcat x)) j)))))))) '((2 2) (3 2) (2 3) (3 3) 2 3 )'(("0" "0") ("" "0") ("0" "") ("" "")("" "0")("" "")))) )))) ) ) s $ ) ) ;_ end of defun The results may differ by drawing settings , angbase & angdir !! (angtos (- pi) 1 4 ) ; "180d0'-0\"" (_dmmss (- pi) 4 ) ;"-180°00'00\"" [EDIT] Upgraded version, with angtos precision [color="green"] ;hp:dmmss ,similar angtos conversion for surveyor jobs angle d.mmss readout ;argument ;ang = real , radians ;prec = integer, precision ;tos = t/nil , to string mode if a non-nil value is supplied output returns a string, else output as a list[/color] (defun hp:dmmss (ang prec tos / str l $) ;;;hanhphuc 24.08.2017 (setq str (angtos (abs ang) 1 prec) l (read (apply 'strcat (list "("(if (minusp ang)"-""") (vl-string-translate "d-'\"" " " (strcat (itoa (+ (* (fix (/ (abs ang) (* 2. pi))) 360) (atoi (setq $ (substr str 1 (vl-string-search "d" str)))) ) ) (vl-string-left-trim $ str) ) ) ")" ) ) ) ) (if tos (apply 'strcat (mapcar ''((a b c) (strcat (if (< (fix (abs a)) 10) "0" "" ) (rtos a 2 c) b ) ) l '("°" "'" "\"") (list 0 0 (if(< prec 4)0 (- prec 4))) ) ;_ end of mapcar ) ;_ end of apply l ) ;_ end of if ) ;_ end of defun (hp:dmmss 2.465538 2 [color="blue"]t[/color])[color="green"]; "141°16'"[/color] (hp:dmmss -2.465538 3 [color="blue"]t[/color])[color="green"]; "-141°15'54\""[/color] (hp:dmmss 3.2745648 4 [color="blue"]t[/color])[color="green"]; "187°37'07\""[/color] (hp:dmmss -5.8827050 5 [color="blue"]t[/color])[color="green"]; "-337°03'15.00\"" [/color] (hp:dmmss -5.8827050 6 [color="blue"]nil[/color])[color="green"]; (-337 3 15.01) [/color] Edited August 24, 2017 by hanhphuc Quote
BIGAL Posted August 22, 2017 Posted August 22, 2017 Thanks changed code to MINS forgot about Minimum. Quote
hanhphuc Posted August 24, 2017 Posted August 24, 2017 (edited) ignarous said: It was mentioned that they are not texts, because I have to perform operations with the DMS angle returned by the function i think i figure out "no texts" ? return a list This code adapted from old thread (defun angltof (l) ;hanhphuc (if (vl-every ''((x) (and (<= 0. x) (< x 60.))) (cdr l)) ((if (minusp (car l)) - +) (angtof (apply 'strcat (mapcar ''((a b c) (strcat (rtos (abs a) 2 c) b)) l '("d" "'" "\"") '(0 0 2)) ) ) ) ) ) ;test dms in list to radian (setq dms '(-123 45 56)) (angltof dms ) ;-2.16012 (angltof '(123 60 56)) ;nil - no good? (defun rad->ldms (ang / str $) ;hanhphuc (setq str (angtos (abs ang) 1 4)) (read (apply 'strcat (list "("(if (minusp ang)"-""") (vl-string-translate "d-'\"" " " (strcat (itoa (+ (* (fix (/ (abs ang) (* 2. pi))) 360) (atoi (setq $ (substr str 1 (vl-string-search "d" str)))) ) ) (vl-string-left-trim $ str) ) ) ")" ) ) ) ) ;test radian to dms list (rad->ldms 1.13456) ;(65 0 20) (rad->ldms (/ pi -1.5)) ;(-120 0 0) (rad->ldms (angltof '(-123 45 55))) ;(-123 45 55) ;SUM TEST (setq sum '(0.304046 0.898362 2.67573 4.23933 6.60628)) (rad->ldms (apply '+ sum )) ;;;(843 36 31) BIGAL said: Thanks changed code to MINS forgot about Minimum. no worries Alan.. your signature always reminds us Edited June 3, 2020 by hanhphuc BBCode tags removed 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.