本帖最后由 树櫴希德 于 2023-6-8 11:55 编辑
- (defun plxyz(e fun / pt p n);多段线节点三维坐标,连续重合点只取一个,根据fuz阀值过滤接近点
- (or(=(type e)'vla-object)(setq e(vlax-ename->vla-object e)))
- (cond((=(setq n(vlax-get-property e'objectname))"AcDbLine")
- (list(vlax-curve-getstartpoint e)(vlax-curve-getendpoint e)))
- ((WCMATCH n"*Polyline")
- (repeat(setq n(fix(+(vlax-curve-getendparam e)(if(=(vlax-get-property e'Closed):vlax-true)0 1))))
- (or(equal(setq n(1- n)p(vlax-curve-getpointatparam e n))(car pt)fun)
- (setq pt(cons p pt))))
- (if(equal(car pt)(last pt)fun)
- (butlast pt)pt))))
- (defun nodekill(e fuz / area pt p1 p2 mj p a b c i l n 1-N Ntriangle);;;控制面积变化率精简多段线节点
- (defun 1-N(fun i n / a);;;第i点的前一个(fun -)或后一个(fun +)有效点
- (while(not(nth(setq i(cond((<= 0(setq a(fun i 1))n)a)((> a n)0)((MINUSP A)N)))pt)))i)
- (defun Ntriangle(i n / a b c d p1 p2 p3 p4 area);去掉第i点,重组相邻三角形数据
- (setq b(1-n - i n)a(1-n - b n)
- c(1-n + i n)d(1-n + c n)
- p1(nth a pt)p2(nth b pt)p3(nth c pt)p4(nth d pt)
- pt(subst nil(nth i pt)pt))
- (list(List b a c(setq area(2area(List p2 p1 p3)))(/(abs area)(distance p1 p3)))
- (List c b d(setq area(2area(List p3 p2 p4)))(/(abs area)(distance p2 p4)))))
- (setq pt(plxyz e 1e-8)area(vlax-curve-getarea e)darea(* area fuz 2)mj 0 n(1-(length pt))
- p1(vl-sort(mapcar(function(lambda(x / i j k a b c)
- (setq i(vl-position x pt)j(1-N - i n)k(1-N + i n)
- b(nth j pt)c(nth k pt)a(2area(List x b c)))
- (List i j k a(/(abs a)(distance b c)))))pt)
- (function(lambda(x y)(<(last x)(last y))))))
- (while(equal mj 0 darea)
- (if(equal(setq a(car p1)mj(+ mj(cadddr a)))0 darea)
- (setq b(assoc(cadr a)p1)p1(vl-remove a p1)p1(vl-remove b p1)
- p1(vl-sort(append(Ntriangle(car a)n)(vl-remove(assoc(caddr a)p1)p1))(function(lambda(x y)(<(last x)(last y))))))))
- (vl-remove 'nil pt))
- (defun 2area(pt)(apply'+(mapcar'(lambda(x y)(-(*(car x)(cadr y))(*(car y)(cadr x))))(cons(last pt)pt)pt)))
|