The code is measuring specified distance by specified segment length typ and return resulting 3d point list,
If a reminder left over typ+reminder, its being tested for its length:
If the left over segment length is smaller or equal to maximum , remove the last point and add the end point to the list, return resulting list.
If the left over segment length is greater than the maximum limit, divide its length into I , and try to pass the test again.
If the left over segment is smaller than minimum than prompt the user and exit.
How can I code it more efficient , shorter , stable?
Thanks
Shay
;_divids length between 2 points by interval
;_retval - a coordinate list
;_s - start point
;_e_endpoint
;_i - interval
(defun measurex ( s e i / a r )
(setq r (list s)
a (angle s e)
)
(repeat (fix (/ (distance s e) i))
(setq r (cons (polar (car r) a i) r))
)
)
;_divids length between 2 points by segment count
;_retval - a coordinate list
;_s - start point
;_e_endpoint
;_i - segment counts
(defun dividex ( s e i / a r sl)
(setq r (list s)
a (angle s e)
sl (/ (distance s e) i) ;
)
(repeat (fix i)
(setq r (cons (polar (car r) a sl) r))
)
)
;_measure segments at a specidied length
;_if there is a reminder, substract the last coordinate from the list
;_add the reminder to the specified length
;_divide it equaly into 2
(defun getTypicalLength (stp etp typ mn mx / dist ml i w f )
(setq i 1)
(if (and (> typ mn) (< typ mx)(>= (distance stp etp) typ))
(if (/= (setq dist (distance (setq stp (cadr (setq ml (measurex stp etp typ)))) etp)) typ ) ;_if there is a reminder
(while (null f) ;_flag.is there a need to loop? t=no nil=yes
(if (>= dist mn) ;_is greater than minimum limit
(if (<= dist mx) ;_is smaller than maxiuum limit
(if (null w) ;_flag. segment were divided?. t=no nil-yes
(setq f t ml (cdr ml) ml (cons etp ml)) ;_flag. no loop is needed. return list+end point
(progn
(setq f t) ;_flag. no loop is needed.
(append (reverse(cdr ml))(cdr(reverse(dividex stp etp i)))) ;_return list+divid seg+reminder equally
)
)
(setq i (1+ i) dist (/ (distance stp etp)i) w t) ;_divid seg when it doesnt meet maximum length, start over
)
(princ "Cannot constract a layout with those limits") ;_stop when seg length doesnt meet minimum length
)
)
ml ;_return list when no reminder left
)
)
)