torcky 发表于 2005-2-10 15:37:00

[原创]比较两多义线图元是否相同

(defun c:w2(/ a1 a2 a1ent a2ent aa1 aa2 a1list a2list templist a1dist a2dist a1distpo-list a1distpo-list-sort maxlist1<BR>                               a2distpo-list a2distpo-list-sort maxlist2 equalflag copya1 transmat copya1list copya1bulge a2list-1 complist<BR>                               xatom n sum e2 e1 i pos xcom ycom bcom a2bulge copya1list copya1bulge complist)<BR>       (setvar "cmdecho" 0)<BR>       (setq a1 (car(entsel)))<BR>       (setq a2 (car(entsel)))<BR>       (setq a1ent (entget a1))<BR>       (setq a2ent (entget a2))<BR>       (command "area" "o" a1)<BR>       (setq aa1 (getvar "area"))<BR>       (command "area" "o" a2)<BR>       (setq aa2 (getvar "area"))<BR>       (setq equalflag nil)<BR>       (if (equal aa1 aa2 0.00001);比较面积<BR>                       (if        (= (cdr (assoc 0 a1ent)) (cdr (assoc 0 a2ent)));比较图元类别<BR>                                       (if (= (cdr (assoc 90 a1ent)) (cdr (assoc 90 a2ent)));比较节点数<BR>        (if (=       (cdr (assoc 70 a1ent)) (cdr (assoc 70 a2ent)));比较封闭性<BR>               (progn<BR>                               (setq a1list (vex a1ent))<BR>                               (setq a1bulge (getbulge a1ent))<BR>                               (setq templist (append (cdr a1list) (list(car a1list))))<BR>                               (setq a1dist (mapcar 'distance a1list templist))<BR>                               (setq a1distpo-list (mapcar 'list a1dist a1list templist))<BR>                               (setq a1distpo-list-sort (vl-sort a1distpo-list (function (lambda (e1 e2) (&gt; (car e1)(car e2))))))<BR>                               (setq maxlist1(getmax a1distpo-list-sort))<BR>                               <BR>                               (setq a2list (vex a2ent))<BR>                               (setq a2bulge (getbulge a2ent))<BR>                               (setq templist (append (cdr a2list) (list(car a2list))))<BR>                               (setq a2dist (mapcar 'distance a2list templist))<BR>                               (setq a2distpo-list (mapcar 'list a2dist a2list templist))<BR>                               (setq a2distpo-list-sort (vl-sort a2distpo-list (function (lambda (e1 e2) (&gt; (car e1)(car e2))))))<BR>                               (setq maxlist2(getmax a2distpo-list-sort))<BR>                               <BR>                               (setq i 0)<BR>                               (while (and (not equalflag) (&lt; i (length maxlist1)))<BR>                                               (setq copya1(vla-copy (vlax-ename-&gt;vla-object a1)))<BR>                                               (setq transmat(fox_align (cdr(car maxlist1)) (cdr(nth i maxlist2))))<BR>;;;                                               (setq transmat(fox_align (cdr(nth i maxlist1)) (cdr(nth i maxlist2))))<BR>                                               (vla-transformby copya1 transmat)<BR>                                               (setq copya1list (vex (entget(vlax-vla-object-&gt;ename copya1))))<BR>                                               (setq copya1bulge (getbulge (entget(vlax-vla-object-&gt;ename copya1))))<BR>                                               (setq a2list-1(list (fix(* 10000(car(car a2list)))) (fix(* 10000(cadr(car a2list))))))<BR>                                               (setq complist (mapcar '(lambda (xatom) (list (fix(* 10000(car xatom))) (fix(* 10000(cadr xatom))))) copya1list))<BR>                                               (if (setq pos(vl-position a2list-1 complist))<BR>                       (repeat pos<BR>                                               (setq copya1list (append (cdr copya1list) (list(car copya1list))))<BR>                                               (setq copya1bulge (append (cdr copya1bulge) (list(car copya1bulge))))<BR>                                               )<BR>                )<BR>                                               (setq sum 0)<BR>                                               (setq xcom(foreach n (mapcar '- (mapcar 'car copya1list)(mapcar 'car a2list)) (setq sum(+ sum (abs n)))))<BR>                                               (setq sum 0)<BR>                                               (setq ycom(foreach n (mapcar '- (mapcar 'cadr copya1list)(mapcar 'cadr a2list)) (setq sum(+ sum (abs n)))))<BR>                                               (setq sum 0)<BR>                                               (setq bcom(foreach n (mapcar '- a2bulge copya1bulge) (setq sum(+ sum (abs n)))))<BR>                                               (if (and (equal 0 xcom 0.0000001)(equal 0 ycom 0.0000001)(equal 0 bcom 0.0000001))<BR>                (setq equalflag 't))<BR>                                               (vla-delete copya1)<BR>                                               (setq i (1+ i))<BR>                                               )<BR>                               )<BR>               )<BR>                                       )<BR>                       )<BR>       )<BR>       (princ equalflag)<BR>       (princ )<BR>)<BR>(defun getbulge(ent / i entlist ent);得到凸度列表<BR>       (setq i 0 entlist '())<BR>       (while (&lt; i (length ent))<BR>                       (if (= 42 (car (nth i ent)))<BR>                                                       (setq entlist (cons (cdr(nth i ent))entlist))<BR>                                       )<BR>                       (setq i (1+ i))<BR>                       )<BR>       (reverse entlist)<BR>       )


(defun vex(ent / i entlist ent);得到节点列表<BR>       (setq i 0 entlist '())<BR>       (while (&lt; i (length ent))<BR>                       (if (= 10 (car (nth i ent)))<BR>                                                       (setq entlist (cons (cdr(nth i ent))entlist))<BR>                                       )<BR>                       (setq i (1+ i))<BR>                       )<BR>       (reverse entlist)<BR>       )


(defun getmax (list-sort / maxlista kl maxlist);得到最大边列表<BR>       (setq maxlista (car list-sort) maxlist '())<BR>       (setq kl 't)<BR>       (while (and kl       list-sort)<BR>                       (setq list-sort (cdr list-sort))<BR>                       (if (equal (car maxlista) (car(car list-sort)) 0.0001)<BR>                                       (progn<BR>                                                       (setq maxlist (cons       maxlista maxlist))<BR>        (setq maxlista (car list-sort))<BR>        )<BR>                                       (progn<BR>        (setq maxlist (cons       maxlista maxlist))<BR>                                                       (setq kl nil)<BR>                                       )<BR>                                       )<BR>                       )<BR>       maxlist<BR>       )


(defun fox_align(a1-p2 a2-p2 / delta-ang mx my sum transmat);得到两图元的转换矩阵<BR>       (setq sum 0)<BR>       (setq a1-po1 (car a1-p2))<BR>       (setq a1-po2 (cadr a1-p2))<BR>       (setq a2-po1 (car a2-p2))<BR>       (setq a2-po2 (cadr a2-p2))<BR>       (setq delta-ang(- (angle a2-po1 a2-po2)       (angle a1-po1 a1-po2)))<BR>       (setq mx (-(car a2-po2)(foreach n       (mapcar '* (list (cos delta-ang) (- 0 (sin delta-ang)) 0) a1-po2) (setq sum(+ sum n)))))<BR>       (setq sum 0)<BR>       (setq my (-(cadr a2-po2)(foreach n       (mapcar '* (list (sin delta-ang) (cos delta-ang) 0) a1-po2) (setq sum(+ sum n)))))<BR>       (setq transmat (vlax-make-safearray vlax-vbdouble '(0 . 3) '(0 . 3)))<BR>       (vlax-safearray-fill transmat (list(list (cos delta-ang) (- 0 (sin delta-ang)) 0 mx)<BR>                                       (list (sin delta-ang) (cos delta-ang) 0 my)<BR>                                       '(0 0 1 0)<BR>                                       '(0 0 0 1))<BR>        )<BR>       transmat<BR>       )

torcky 发表于 2005-2-18 20:32:00

<b>两多义线图元若相同函数返回T,否则返回Nil</b>

HuaiYu 发表于 2005-7-10 20:52:00

太好了,很好的东东,


我要好好看看


你是不是传说中的TJZ啊?

HuaiYu 发表于 2005-7-17 22:07:00

(defun c:ww (/ en_a en_b aa a1 bb b1 a_clock b_clock)<BR>&nbsp; (setq&nbsp;en_a (car (entsel "\n Please select a lwpolyline object a:&nbsp; "))<BR>&nbsp;en_b (car (entsel "\n Please select a lwpolyline object b:&nbsp; "))<BR>&nbsp; ) ;_ Endsetq<BR>&nbsp; (princ "*********")<BR>&nbsp; (setq a (get_data en_a))<BR>&nbsp; (setq b (get_data en_b))<BR>&nbsp; (setq&nbsp;aa (get_list (car a))<BR>&nbsp;a1 (cadr a)&nbsp;&nbsp;&nbsp;;a1=the list of bulge a<BR>&nbsp;a1 (mapcar '(lambda (x) (rtos x 2 4)) a1)<BR>&nbsp;a1 (mapcar '(lambda (x) (atof x)) a1)<BR>&nbsp; ) ;_ Endsetq<BR>&nbsp; (setq&nbsp;bb (get_list (car b))<BR>&nbsp;b1 (cadr b)&nbsp;&nbsp;&nbsp;; b1= the list of bulge b<BR>&nbsp;b1 (mapcar '(lambda (x) (rtos x 2 4)) b1)<BR>&nbsp;b1 (mapcar '(lambda (x) (atof x)) b1)<BR>&nbsp; ) ;_ Endsetq<BR>&nbsp; (setq a_clock (get_clock aa))&nbsp;&nbsp;; 0-clock 1-counterclock ; 0 抖皐&nbsp; 1 は皐<BR>&nbsp; (setq b_clock (get_clock bb))<BR>&nbsp; (if (equal a_clock b_clock)&nbsp;&nbsp;; if the same clock<BR>&nbsp;&nbsp;&nbsp; (progn ;;judge the dist-----angle<BR>&nbsp;&nbsp;&nbsp; (if (not (equal aa bb))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq bb (compare aa bb))<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endif<BR>&nbsp;&nbsp;&nbsp; ;;judge the bulge<BR>&nbsp;&nbsp;&nbsp; (if (not (equal a1 b1))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq b1 (compare a1 b1))<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endif<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endprogn<BR>&nbsp;&nbsp;&nbsp; ;; if not the same clock<BR>&nbsp;&nbsp;&nbsp; (progn ;;judge the dist----angle<BR>&nbsp;&nbsp;&nbsp; (setq bb (get_list (reverse (car b))))<BR>&nbsp;&nbsp;&nbsp; (if (not (equal aa bb))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq bb (compare aa bb))<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endif<BR>&nbsp;&nbsp;&nbsp; ;;judge the bulge<BR>&nbsp;&nbsp;&nbsp; (setq b1 (reverse (mapcar '(lambda (x) (- 0 x)) b1)))<BR>&nbsp;&nbsp;&nbsp; (if (not (equal a1 b1))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq b1 (compare a1 b1))<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endif<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endprogn<BR>&nbsp; ) ;_ Endif<BR>&nbsp; ;; if dist--angle same and list-bulge then alert ok else alert no<BR>&nbsp; (if (and (equal aa bb) (equal a1 b1))<BR>&nbsp;&nbsp;&nbsp; (alert "OK")<BR>&nbsp;&nbsp;&nbsp; (alert "NO")<BR>&nbsp; ) ;_ Endif<BR>&nbsp; (prin1)<BR>) ;_ Enddefun<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(defun compare (aa bb / flag i bb1)<BR>&nbsp; (setq&nbsp;flag 1<BR>&nbsp;i 0<BR>&nbsp; ) ;_ Endsetq<BR>&nbsp; (while (= flag 1)<BR>&nbsp;&nbsp;&nbsp; (setq bb1 (append (cdr bb) (list (car bb))))<BR>&nbsp;&nbsp;&nbsp; (setq i (1+ i))<BR>&nbsp;&nbsp;&nbsp; (if&nbsp;(equal aa bb1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq flag 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq bb bb1)<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endif<BR>&nbsp;&nbsp;&nbsp; (if&nbsp;(= i (length aa))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq flag 0)<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endif<BR>&nbsp; ) ;_ Endwhile<BR>&nbsp; bb1<BR>) ;_ Enddefun<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(defun get_list&nbsp;(pt1 / list_d list_b i p_i p_i1 p_i2 dist ang21 ang10 ang)<BR>&nbsp; (setq&nbsp;list_d '()<BR>&nbsp;list_b '()<BR>&nbsp;i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<BR>&nbsp;pt1&nbsp;&nbsp;&nbsp; (append pt1 (list (car pt1)) (list (cadr pt1)))<BR>&nbsp; ) ;_ Endsetq<BR>&nbsp; (repeat (- (length pt1) 2)<BR>&nbsp;&nbsp;&nbsp; (setq p_i&nbsp; (nth i pt1)<BR>&nbsp;&nbsp; p_i1&nbsp; (nth (+ i 1) pt1)<BR>&nbsp;&nbsp; p_i2&nbsp; (nth (+ i 2) pt1)<BR>&nbsp;&nbsp; dist&nbsp; (distance p_i1 p_i)<BR>&nbsp;&nbsp; ang21&nbsp; (angle p_i1 p_i2)<BR>&nbsp;&nbsp; ang10&nbsp; (angle p_i1 p_i)<BR>&nbsp;&nbsp; ang&nbsp; (- ang10 ang21)<BR>&nbsp;&nbsp; ang&nbsp; (angtos ang 0 4)<BR>&nbsp;&nbsp; ang&nbsp; (atof ang)<BR>&nbsp;&nbsp; dist&nbsp; (rtos dist 2 4)<BR>&nbsp;&nbsp; dist&nbsp; (atof dist)<BR>&nbsp;&nbsp; list_d (append list_d (list (list dist ang)))<BR>&nbsp;&nbsp; i&nbsp; (1+ i)<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endsetq<BR>&nbsp; ) ;_ Endrepeat<BR>&nbsp; list_d<BR>) ;_ Enddefun<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(defun get_data&nbsp;(en / list_pt list_b en_data i en_i)<BR>&nbsp; (setq&nbsp;list_pt&nbsp;'()<BR>&nbsp;list_b&nbsp;'()<BR>&nbsp;en_data&nbsp;(entget en)<BR>&nbsp;i&nbsp;0<BR>&nbsp; ) ;_ Endsetq<BR>&nbsp; (repeat (length en_data)<BR>&nbsp;&nbsp;&nbsp; (setq en_i (nth i en_data))<BR>&nbsp;&nbsp;&nbsp; (if&nbsp;(= (car en_i) 10)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (progn<BR>;;;&nbsp;(getint "\n PLease press any key to continue: ")<BR>;;;&nbsp;(command "circle" (cdr en_i) 3)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq list_pt (append list_pt (list (cdr en_i)))<BR>&nbsp;&nbsp;&nbsp;&nbsp; list_b&nbsp; (append list_b (list (cdr (nth (+ i 3) en_data))))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) ;_ Endsetq<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) ;_ Endprogn<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endif<BR>&nbsp;&nbsp;&nbsp; (setq i (1+ i))<BR>&nbsp; ) ;_ Endrepeat<BR>&nbsp; (list list_pt list_b)<BR>) ;_ Enddefun<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(defun get_clock (cc / k)<BR>&nbsp; (setq k 0)<BR>&nbsp; (foreach n cc<BR>&nbsp;&nbsp;&nbsp; (if&nbsp;(&gt; (cadr n) 180)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq k (1+ k))<BR>&nbsp;&nbsp;&nbsp; ) ;_ Endif<BR>&nbsp; ) ;_ Endforeach<BR>&nbsp; (if (&gt; k (/ (length cc) 2))&nbsp;&nbsp;; 0 抖皐&nbsp; 1 は皐<BR>&nbsp;&nbsp;&nbsp; 0<BR>&nbsp;&nbsp;&nbsp; 1<BR>&nbsp; ) ;_ Endif<BR>) ;_ Enddefun<BR>

HuaiYu 发表于 2005-7-17 22:08:00

唐,看看我的

torcky 发表于 2005-7-19 17:14:00

<P>今天下午研究了一下<A name=45694><FONT color=#000066><B>HuaiYu</B></FONT></A>君的大作,厉害!!</P>
<P>&nbsp;比拙作简洁缜密,佩服!!!</P>

洋葱老爹 发表于 2005-8-1 13:40:00

<P>L看不太懂,有vba的就好啦......期待中!!!</P>

舟自横 发表于 2005-9-25 09:07:00

本帖最后由 作者 于 2005-9-25 9:28:22 编辑 <br /><br /> <P>其实用不了这么麻烦..</P>
<P>单就复线而言只要判断顶点的增量坐标(相对坐标列表,即后一点相对于前一点的坐标增量)是否一致.并且凸度列表一致就可以了..</P>
<P>判断很多也是没有意义的看一下这段</P>
<P>(defun hy_samepoly(en1 en2);;t nil相同返回T不同返回NIL<BR>&nbsp;&nbsp; (if (and (equal (mapcar '(lambda(x y) (list (- (car y) (car x)) (- (cadr y) (cadr x))))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (massoc 10 (entget en1)) (append (cdr (massoc 10 (entget en1)))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(list (car (massoc 10 (entget en1))))))<BR>&nbsp;&nbsp;&nbsp;&nbsp; (mapcar '(lambda(x y) (list (- (car y) (car x)) (- (cadr y) (cadr x))))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (massoc 10 (entget en2)) (append (cdr (massoc 10 (entget en2)))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(list (car (massoc 10 (entget en2)))))) 0.000001)<BR>&nbsp;&nbsp;&nbsp;&nbsp; (equal (massoc 42 (entget en1)) (massoc 42 (entget en2)) 0.000001)<BR>&nbsp;&nbsp;&nbsp;&nbsp; )<BR>&nbsp;&nbsp;&nbsp;&nbsp; t nil)</P>
<P>)</P>
<P>(defun massoc (key alist / x nlist)<BR>&nbsp; (foreach x alist<BR>&nbsp;&nbsp;&nbsp; (if (eq key (car x))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq nlist (cons (cdr x) nlist))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<BR>&nbsp;&nbsp;&nbsp; )<BR>&nbsp;&nbsp; )</P>

无痕 发表于 2005-10-8 00:32:00

怎么随便拿两个不同形状的多义线也返回T??
知道了:(defun massoc (key alist / x nlist)
(foreach x alist
    (if (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
      )
    )nlist
   )

无痕 发表于 2005-10-8 01:19:00

(defun c:tt2 (/ l1 l2 vs1 vs2 bg1 bg2 v b)
(setq e1 (car(entsel))
e2 (car(entsel))
l1 (entget e1)
l2 (entget e2)
)
(setq vs1 (mapcar 'cdr (vl-remove-if-not '(lambda(x)(= 10 (car x))) l1))
vs2 (mapcar 'cdr (vl-remove-if-not '(lambda(x)(= 10 (car x))) l2))
bg1 (mapcar 'cdr (vl-remove-if-not '(lambda(x)(= 42 (car x))) l1))
bg2 (mapcar 'cdr (vl-remove-if-not '(lambda(x)(= 42 (car x))) l2))
v (mapcar '(lambda(x y)(mapcar '- x y)) vs1 vs2)
b (mapcar '- bg1 bg2))
(and (apply '= (mapcar 'car v))
       (apply '= (mapcar 'cadr v))
       (apply '= (cons 0 b)))
)
页: [1] 2
查看完整版本: [原创]比较两多义线图元是否相同