本帖最后由 llsheng_73 于 2017-10-20 15:04 编辑
对于封闭多段线,只要是凹点,那么该点及相邻两点组成的三角形的方向必然与该多段线整体方向相反
- (defun plxyz(e fuz / i p pt);多段线节点三维坐标,连续重合点只取一个,根据fuz阀值过滤接近点
- (setq i(-(vlax-curve-getendparam e)(logand(cdr(assoc 70(entget e)))1)-1))
- (while(setq i(1- i)p(vlax-curve-getpointatparam e i))
- (setq pt(if(equal(car pt)p fuz)pt(cons p pt))))
- )
- (defun 2area(pt)
- (apply'+(mapcar'(lambda(x y)(-(*(car x)(cadr y))(*(car y)(cadr x))))(cons(last pt)pt)pt)))
- (defun pldir(e / p p1 p2);;e多段线图元或者对象
- (vla-GetBoundingBox(if(=(type e)'ename)(vlax-ename->vla-object e)e)'p1'p2)
- (mapcar'set'(p1 p2)(mapcar'vlax-safearray->list(list p1 p2)))
- (2area(Mapcar'cdr(vl-sort(mapcar'(lambda(x)(setq p(vlax-curve-getclosestpointto e x))
- (cons(vlax-curve-getparamatpoint e p)p))
- (list(list(car p1)(cadr p2))p1(list(car p2)(cadr p1))p2))
- '(lambda(x y)(<(car x)(car y)))))))
- (defun Pitpl(e / a p)
- (setq p(plxyz e 0)
- a(pldir e))
- (vl-some'(lambda(x y z)(<(*(2area(list x y z))a)0))(cons(last p)p)p(cdr(append p(list(car p)))))
- )
- (defun c:tt(/ s)
- (if(setq s(ssget'((0 . "lwpolyline")(-4 . "&")(70 . 1))))
- (foreach x(vl-remove'nil(mapcar'(lambda(x)(if(=(type(cadr x))'ename)(cadr x)))(ssnamex s)))
- (if(Pitpl x)
- (entmod(setq x(entget x)x(if(assoc 62 x)(subst'(62 . 1)(assoc 62 x)x)(append x'((62 . 1))))))))))
其实还有更简单的办法,凹点内角大于必定大于180,如果用angle来计算两条相邻边的角度后相减来得到内角,实际上是比较烦的。好在(n-1),n,(n+1)这样连续三点的内角可以把(n+1)转换到到n(n-1)直线,根据得到的坐标的来判断是否大于180,当然,这个判断的条件实际上也会因为点的方向不一样而完全相反,
- (defun plinexy(e)
- (mapcar'cdr(vl-remove-if'(lambda(x)(/=(car x)10))(entget e))))
- (defun 2area(pt / a)
- (setq a(apply'+(mapcar'(lambda(x y)(-(*(car x)(cadr y))(*(car y)(cadr x))))(cons(last pt)pt)pt))a(/ a(abs a))))
- (defun pitang(p p1 p2 a);;角p2 p1 p不大于180,a为给定方向
- (<(*(car(trans(mapcar'- p1 p) 0 (mapcar'- p1 p2)))a)0))
- (defun pitpl(e / p a)
- (setq p(plinexy e)
- a(2area p)
- p(vl-some'(lambda(x y z)(pitang x y z a))(cons(last p)p)p(cdr(append p(list(car p)))))))
- (defun c:tt(/ s)
- (if(setq s(ssget'((0 . "lwpolyline")(-4 . "&")(70 . 1))))
- (foreach x(vl-remove'nil(mapcar'(lambda(x)(if(=(type(cadr x))'ename)(cadr x)))(ssnamex s)))
- (if(Pitpl x)
- (entmod(setq x(entget x)x(if(assoc 62 x)(subst'(62 . 1)(assoc 62 x)x)(append x'((62 . 1))))))))))
|