;; ! **************************************************************************** ;; ! Function : Weed a list based on inter-vertex distance AND angular deflection ;; ! between the points. ;; ! The deflection angle is considered to be 'Back' i.e the angle ;; ! checked is between the CurPt, PrevPt and NextPt. ;; ! Arguments: ;; ! 'vlist' - List to be weeded ;; ! 'WeedDist' - Maximum Distance allowable between points. ;; ! 'WeedAng' - Deflection angle to check between points. ;; ! 'MeasD' - Measure Distance in 2D or 3D (accepts "Slope" or ;; ! "Horiz") ;; ! Return : Returns two lists, the first one is a list of retained points ;; ! and the second is a list of points which were weeded along with their ;; ! list array index (starting from 0). ;; ! Comments : The first and last points of the list will never be weeded ;; ! Updated : March 11, 2001 ;; ! (C) 1999-2004, Four Dimension Technologies, Bangalore ;; ! e-mail : rakesh.rao@4d-technologies.com ;; ! Web : www.4d-technologies.com ;; ! **************************************************************************** (defun GE_Dist&AngWeed_Back( vlist WeedDist WeedAng MeasD / _vlist nverts CurAng PrevAng ang cnt pt2 len CurPt DelLst NextPt PrevPt Weeded ) (setq nverts (length vlist) DelLst '() ) (if (<= nverts 2) (setq _vlist vlist) (progn (setq cnt 1 CurPt (nth 0 vlist) ; Make sure that the first [and last] point is not weeded _vlist '() ) (repeat nverts (setq Weeded nil) (cond ((= cnt 1) (setq PrevPt nil NextPt (nth cnt vlist) ) ) ((= cnt nverts) (setq NextPt nil) ) (T (setq NextPt (nth cnt vlist)) ) ) (if NextPt (progn (if (= MeasD "Slope") (setq len (distance CurPt NextPt)) (setq len (distance (list (car CurPt) (cadr CurPt) 0.0) (list (car NextPt) (cadr NextPt) 0.0) ) ) ) (if (> len WeedDist) (progn (if PrevPt (progn (setq ang (GE_GetIncludedAngle CurPt PrevPt NextPt)) (if (and ang (< ang WeedAng)) (setq DelLst (cons (list cnt NextPt) DelLst) _vlist (cons CurPt _vlist) Weeded T ) (setq _vlist (cons CurPt _vlist) PrevPt CurPt CurPt NextPt )) ) (setq _vlist (cons CurPt _vlist) PrevPt CurPt CurPt NextPt )) ) (setq DelLst (cons (list cnt NextPt) DelLst) Weeded T )) )) (setq cnt (1+ cnt)) ) ;; Make sure that the last point is not weeded (setq _vlist (append (reverse _vlist) (list CurPt))) (if (not (equal (last vlist) (last _vlist))) (setq _vlist (append _vlist (list (last vlist)))) ) (setq _vlist (GE_DistWeed _vlist 0.0 "Slope")) (if _vlist (setq _vlist (car _vlist)) ) (setq DelLst (reverse DelLst)) )) (if (>= (length _vlist) 1) (list _vlist DelLst) nil ) )