This is just fun to exercise.
I'm trying to simulate the polar.
Then I will read the "F8" and "F10" keys.
What is your opinion?
Would they do it differently?
This is very fun and rewarding.
(defun c:test ()
;; String to List - Lee Mac
;; Separates a string using a given delimiter
;; str - [str] String to process
;; del - [str] Delimiter by which to separate the string
;; Returns: [lst] List of strings
(defun LM:str->lst (str del / pos)
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos)
(LM:str->lst (substr str (+ pos 1 (strlen del))) del)
) ;_ >cons
(list str)
) ;_ >if
) ;_ >defun
;; Unique - Lee Mac
;; Returns a list with duplicate elements removed.
(defun LM:Unique (l)
(if l
(cons (car l) (LM:Unique (vl-remove (car l) (cdr l))))
) ;_ >if
) ;_ >defun
(defun polarline (p / g)
(while (= 5 (car (setq g (grread t 13 0))))
(redraw)
(setq ang (angle p (setq pt2 (cadr g)))
closestAngle nil
) ;_ >setq
(setq listAngles (list ang))
(setq listAngles (vl-sort(append listAngles polarAngles)'<))
(setq position (vl-position ang listAngles))
(if (= position 0)
(setq before (last listAngles))
(setq before (nth (- position 1) listAngles))
) ;_ >if
(if (= ang (last listAngles))
(setq after (car listAngles))
(setq after (nth (+ position 1) listAngles))
) ;_ >if
(cond
((<=
(abs
(- ang before)
) ;_ >abs
magneticFactor
) ;_ ><=
(setq ang before
trackline t
) ;_ >setq
)
((<=
(abs
(- ang after)
) ;_ >abs
magneticFactor
) ;_ ><=
(setq ang after
trackline t
) ;_ >setq
)
) ;_ >cond
(redraw)
(if trackline
(progn
(grdraw p (setq pt2(polar p ang (distance p pt2))) 1)
(grdraw pt2 (polar pt2 ang tracklineDist) 3)
)
(grdraw p (polar p ang (distance p pt2)) 1)
) ;_ >if
(setq trackline nil)
) ;_ >while
) ;_ >defun
; converts degrees to radians
(defun deg2rad(d) (* pi (/ d 180.0)))
(setq ang (getvar 'POLARANG) ;increment angles
magneticFactor (deg2rad 3) ;to simulate magnetic
tracklineDist 10000 ;lenght of track line
nextAngle 0.0
incrementAngles '()
additionalAngles '()
polarAngles '()
orthogonalAngles '(0.0 1.5708 3.14159 4.71239)
listAngles '() ;temporary list
) ;_ >setq
(while (< nextAngle (* pi 2))
(setq nextAngle (+ nextAngle ang))
(if (< nextAngle (* pi 2))
(progn
(setq incrementAngles (append incrementAngles (list nextAngle)))
(princ nextAngle)
) ;_ >progn
) ;_ >if
) ;_ >while
(setq additionalAngles
(append additionalAngles
(mapcar
(function
(lambda (ang)
(deg2rad (atof ang))
) ;_ >lambda
) ;_ >function
(LM:str->lst (getvar 'POLARADDANG) ";")
) ;_ >mapcar
) ;_ >append
) ;_ >setq
(setq polarAngles (append polarAngles incrementAngles))
(setq polarAngles (append polarAngles orthogonalAngles))
(setq polarAngles (append polarAngles additionalAngles))
(setq polarAngles (vl-sort(LM:Unique polarAngles)'<))
(polarline (getpoint "\nBase Point: "))
(princ)
) ;_ >defun