TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mohobrien on May 28, 2008, 05:31:13 PM
-
I have a pline that defines the boundary of a parcel. The pline is zero width and no special properties. I want to simplify the pline so that only major changes of direction, say more than 45° will be shown. All bends in the line are close to 90° so if I use 45 I should get what I want. I'm not interested in how far apart the vertices are. This little snippet is what I am using to weed the extra vertices. Most of the time it works, but sometimes it misses vetices to remove and sometimes removes what it shouldn't. I think it is a problem with my angle test. Any ideas? finalcoordlist is just that and newcoordlist is the unweeded list.
;;; remove vertices if major change in direction
(setq finalcoordlist
newcoordlist
counter 0
)
(repeat (- (length newcoordlist) 2)
(setq pt1 (nth counter newcoordlist))
(setq pt2 (nth (+ counter 1) newcoordlist))
(setq pt3 (nth (+ counter 2) newcoordlist))
(if
(< (abs (- (angle pt1 pt2) (angle pt2 pt3)))
(* (/ 45.0 180.0) pi)
)
(setq finalcoordlist
(vl-remove (nth (+ counter 1) newcoordlist)
finalcoordlist
)
counter (1+ counter)
)
(setq counter (1+ counter))
)
)
-
Hi , can you upload some dwg sample .?
-
Make use of the function vlax-curve-getFirstDeriv like this
(defun C:TEST ()
(vl-load-com)
(setq curve (car (entsel "\nSelect polyline: ")))
(setq end_param (vlax-curve-getendparam curve))
(setq par 0)
(repeat (fix end_param)
(print (angle '(0 0) (vlax-curve-getFirstDeriv curve par)))
(setq par (1+ par))
)
(princ)
)
-
;;;Hi Cab I did a test with your lisp , an it give not the , say, included angle among two consecutive lines .
;;;This is so, because the first derivative [ FD ] give the tangent of a curve at that point,
;;or also it give the idea how the curve is growing or decaying at that point.
;;;When curve is a line , it give the tangent at that point that in this case is the same as the line angle.
;;;Also in this case , I do not know if ACAD take the value for the ending line or starting line at a given parameter.
;;;I think that if we take the the FD at ( - param 0.1) , and at (+ param 0.1) , it will give 2 angles , and from it,
;; we can get angle between the lines.Not so sure.
;;;I'm doing now some test .
;;;From it I knew that the FD at Param give the angle for the after the param
-
DEVITG,
Try this code:
(defun C:TEST (/ curve end_param par MinAng LastAng RemoveLst)
(vl-load-com)
(setq curve (car (entsel "\nSelect polyline: ")))
(setq end_param (vlax-curve-getendparam curve))
(setq par 0
MinAng (/ pi 4) ; 45 deg
)
(repeat (fix end_param)
(cond
((null LastAng) ; get the ang of the first segment
(setq LastAng (angle '(0 0) (vlax-curve-getFirstDeriv curve par))))
((< (abs (- LastAng
(setq LastAng (angle '(0 0) (vlax-curve-getFirstDeriv curve par)))))
MinAng)
(setq RemoveLst (cons par RemoveLst))
)
)
(setq par (1+ par))
)
(if RemoveLst ; need to remove these vertex
(princ RempveLst)
)
(princ)
)
-
Hi Cab, please can you check it on this dwg .
I did it , and I got NIL
maybe I´m doing something wrong.
-
Yes, all those angles are greater than 45 degrees.
See attached drawing.
-
Hi Cab , I toke a bad concept ,
I thought it was internal angles at the polyline .
Now I got it, it was deviation angle from the prior segment .
cause my poor English.
-
OK 8-)
-
Hi Cad , and how it can be get the "internal" angle of a poly ?
-
Hi Cad , and how it can be get the "internal" angle of a poly ?
Cad? Who is it?
-
Hi Cad , and how it can be get the "internal" angle of a poly ?
Cad? Who is it?
Sorry , a typo error , because CAB know a lot of CAD , I had miss spelling or lapsus, or Fehlleistung in german .