[原创]比较两多义线图元是否相同
(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) (> (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) (> (car e1)(car e2))))))<BR> (setq maxlist2(getmax a2distpo-list-sort))<BR> <BR> (setq i 0)<BR> (while (and (not equalflag) (< i (length maxlist1)))<BR> (setq copya1(vla-copy (vlax-ename->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->ename copya1))))<BR> (setq copya1bulge (getbulge (entget(vlax-vla-object->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 (< 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 (< 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> ) <b>两多义线图元若相同函数返回T,否则返回Nil</b> 太好了,很好的东东,
我要好好看看
你是不是传说中的TJZ啊? (defun c:ww (/ en_a en_b aa a1 bb b1 a_clock b_clock)<BR> (setq en_a (car (entsel "\n Please select a lwpolyline object a: "))<BR> en_b (car (entsel "\n Please select a lwpolyline object b: "))<BR> ) ;_ Endsetq<BR> (princ "*********")<BR> (setq a (get_data en_a))<BR> (setq b (get_data en_b))<BR> (setq aa (get_list (car a))<BR> a1 (cadr a) ;a1=the list of bulge a<BR> a1 (mapcar '(lambda (x) (rtos x 2 4)) a1)<BR> a1 (mapcar '(lambda (x) (atof x)) a1)<BR> ) ;_ Endsetq<BR> (setq bb (get_list (car b))<BR> b1 (cadr b) ; b1= the list of bulge b<BR> b1 (mapcar '(lambda (x) (rtos x 2 4)) b1)<BR> b1 (mapcar '(lambda (x) (atof x)) b1)<BR> ) ;_ Endsetq<BR> (setq a_clock (get_clock aa)) ; 0-clock 1-counterclock ; 0 抖皐 1 は皐<BR> (setq b_clock (get_clock bb))<BR> (if (equal a_clock b_clock) ; if the same clock<BR> (progn ;;judge the dist-----angle<BR> (if (not (equal aa bb))<BR> (setq bb (compare aa bb))<BR> ) ;_ Endif<BR> ;;judge the bulge<BR> (if (not (equal a1 b1))<BR> (setq b1 (compare a1 b1))<BR> ) ;_ Endif<BR> ) ;_ Endprogn<BR> ;; if not the same clock<BR> (progn ;;judge the dist----angle<BR> (setq bb (get_list (reverse (car b))))<BR> (if (not (equal aa bb))<BR> (setq bb (compare aa bb))<BR> ) ;_ Endif<BR> ;;judge the bulge<BR> (setq b1 (reverse (mapcar '(lambda (x) (- 0 x)) b1)))<BR> (if (not (equal a1 b1))<BR> (setq b1 (compare a1 b1))<BR> ) ;_ Endif<BR> ) ;_ Endprogn<BR> ) ;_ Endif<BR> ;; if dist--angle same and list-bulge then alert ok else alert no<BR> (if (and (equal aa bb) (equal a1 b1))<BR> (alert "OK")<BR> (alert "NO")<BR> ) ;_ Endif<BR> (prin1)<BR>) ;_ Enddefun<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(defun compare (aa bb / flag i bb1)<BR> (setq flag 1<BR> i 0<BR> ) ;_ Endsetq<BR> (while (= flag 1)<BR> (setq bb1 (append (cdr bb) (list (car bb))))<BR> (setq i (1+ i))<BR> (if (equal aa bb1)<BR> (setq flag 0)<BR> (setq bb bb1)<BR> ) ;_ Endif<BR> (if (= i (length aa))<BR> (setq flag 0)<BR> ) ;_ Endif<BR> ) ;_ Endwhile<BR> bb1<BR>) ;_ Enddefun<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(defun get_list (pt1 / list_d list_b i p_i p_i1 p_i2 dist ang21 ang10 ang)<BR> (setq list_d '()<BR> list_b '()<BR> i 0<BR> pt1 (append pt1 (list (car pt1)) (list (cadr pt1)))<BR> ) ;_ Endsetq<BR> (repeat (- (length pt1) 2)<BR> (setq p_i (nth i pt1)<BR> p_i1 (nth (+ i 1) pt1)<BR> p_i2 (nth (+ i 2) pt1)<BR> dist (distance p_i1 p_i)<BR> ang21 (angle p_i1 p_i2)<BR> ang10 (angle p_i1 p_i)<BR> ang (- ang10 ang21)<BR> ang (angtos ang 0 4)<BR> ang (atof ang)<BR> dist (rtos dist 2 4)<BR> dist (atof dist)<BR> list_d (append list_d (list (list dist ang)))<BR> i (1+ i)<BR> ) ;_ Endsetq<BR> ) ;_ Endrepeat<BR> list_d<BR>) ;_ Enddefun<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(defun get_data (en / list_pt list_b en_data i en_i)<BR> (setq list_pt '()<BR> list_b '()<BR> en_data (entget en)<BR> i 0<BR> ) ;_ Endsetq<BR> (repeat (length en_data)<BR> (setq en_i (nth i en_data))<BR> (if (= (car en_i) 10)<BR> (progn<BR>;;; (getint "\n PLease press any key to continue: ")<BR>;;; (command "circle" (cdr en_i) 3)<BR> (setq list_pt (append list_pt (list (cdr en_i)))<BR> list_b (append list_b (list (cdr (nth (+ i 3) en_data))))<BR> ) ;_ Endsetq<BR> ) ;_ Endprogn<BR> ) ;_ Endif<BR> (setq i (1+ i))<BR> ) ;_ Endrepeat<BR> (list list_pt list_b)<BR>) ;_ Enddefun<BR>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<BR>(defun get_clock (cc / k)<BR> (setq k 0)<BR> (foreach n cc<BR> (if (> (cadr n) 180)<BR> (setq k (1+ k))<BR> ) ;_ Endif<BR> ) ;_ Endforeach<BR> (if (> k (/ (length cc) 2)) ; 0 抖皐 1 は皐<BR> 0<BR> 1<BR> ) ;_ Endif<BR>) ;_ Enddefun<BR> 唐,看看我的 <P>今天下午研究了一下<A name=45694><FONT color=#000066><B>HuaiYu</B></FONT></A>君的大作,厉害!!</P>
<P> 比拙作简洁缜密,佩服!!!</P> <P>L看不太懂,有vba的就好啦......期待中!!!</P> 本帖最后由 作者 于 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> (if (and (equal (mapcar '(lambda(x y) (list (- (car y) (car x)) (- (cadr y) (cadr x))))<BR> (massoc 10 (entget en1)) (append (cdr (massoc 10 (entget en1)))<BR> (list (car (massoc 10 (entget en1))))))<BR> (mapcar '(lambda(x y) (list (- (car y) (car x)) (- (cadr y) (cadr x))))<BR> (massoc 10 (entget en2)) (append (cdr (massoc 10 (entget en2)))<BR> (list (car (massoc 10 (entget en2)))))) 0.000001)<BR> (equal (massoc 42 (entget en1)) (massoc 42 (entget en2)) 0.000001)<BR> )<BR> t nil)</P>
<P>)</P>
<P>(defun massoc (key alist / x nlist)<BR> (foreach x alist<BR> (if (eq key (car x))<BR> (setq nlist (cons (cdr x) nlist))<BR> )<BR> )<BR> )</P> 怎么随便拿两个不同形状的多义线也返回T??
知道了:(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)nlist
)
(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