fallrain 发表于 2004-6-10 10:39:00

[LISP]请帮我的程序指出错误

我的程序是在选择的边界内部间隔10米画一个圆。我的大致思想是在选择边界后,在选择一内部点。然后用一个二重循环得到点。在点 画圆。点的得到是在内部点的基础上分x和y累加累减,用一个测试在内部的函数(zn)来控制循环的结束。但是我的程序不能运用,不知道问题出在那里。请大家帮帮忙,在此谢谢了!!!


(defun c:tc()


<BR>(defun zn (/                plendpt                       x_lst               e               op<BR>                                       n                fst_pt                       int_num                       online       pc<BR>                                       pn                min_num                       edge_int_num               pt_online_num<BR>                                       op1 )<BR>       (setq min_num 0.0001)<BR>       (princ "\n选择边界:")<BR>       (while (not e) (setq e (car (entsel))))<BR>       (if (= "LWPOLYLINE" (cdr (assoc 0 (entget e))))<BR>                       (progn<BR>                                       (redraw e 3)<BR>                                       (while (not op) (setq op (getpoint "\n请拾取边界内部点:")))<BR>                                       (foreach n (entget e)<BR>        (if (= 10 (car n))<BR>               (if plendpt<BR>                               (setq plendpt (append plendpt (list (cdr n))))<BR>                               (setq plendpt (list (cdr n)))<BR>               )<BR>        )<BR>                                       )<BR>                                       (setq X_lst (mapcar '(lambda (x) (car x)) plendpt))<BR>                                       (setq delta_X (abs (- (apply 'max x_lst) (car op))))<BR>                                       (setq plendpt               (append plendpt (list (nth 0 plendpt)))<BR>                               edge_int_num       0<BR>                               pt_online_num 0<BR>                                       )<BR>                                       (while (&gt; (length plendpt) 1)<BR>        (setq pc (nth 0 plendpt)<BR>                                               pn (nth 1 plendpt)<BR>        )<BR>        (setq op1 (polar op 0 (* delta_x 2)))<BR>        (if (inters op<BR>                                       op1<BR>                                       pc<BR>                                       pn<BR>                               )


               (setq edge_int_num (+ 1 edge_int_num))<BR>        )<BR>        (if (equal (+ (distance op pc) (distance pc op1))<BR>                               (distance op op1)<BR>                                                                                       min_num)<BR>               (setq pt_online_num (+ 1 pt_online_num))<BR>        )


        (if (equal (+ (distance op pc) (distance op pn))<BR>                               (distance pc pn)<BR>                               min_num<BR>                               )<BR>               (setq online "t")<BR>        )<BR>        (setq plendpt (cdr plendpt))<BR>                                       )<BR>                                       (redraw e 4)<BR>                               <BR>                                       )<BR>                       )<BR>       )





<BR>       (setq x (car p0))<BR>       (setq y (cadr p0))<BR>       (zn)<BR>                       (while (= (rem (+ pt_online_num edge_int_num) 2) 1)<BR>                                                               (zn)<BR>                                                               (while (= (rem (+ pt_online_num edge_int_num) 2) 1)<BR>                                                               (command "circle" p0 1 "" )<BR>                                                               (setq x (+ x 10))       <BR>                                                               (setq p0 (list x y))<BR>                                                                                                                                       )


               (setq y (+ y 10))       <BR>               (setq p0 (list x y))<BR>       (command "circle" p0 1 "" )<BR>                                       )<BR>               (while (= (rem (+ pt_online_num edge_int_num) 2) 1)<BR>                                                               (zn)<BR>                                                               (while (= (rem (+ pt_online_num edge_int_num) 2) 1)<BR>                                                               (command "circle" p0 1 "" )<BR>                                                               (setq x (+ x 10))       <BR>                                                               (setq p0 (list x y))<BR>                                                                                                                                       )


               (setq y (- y 10))       <BR>               (setq p0 (list x y))<BR>       (command "circle" p0 1 "" )<BR>                                                       )<BR>       (while (= (rem (+ pt_online_num edge_int_num) 2) 1)<BR>                                                               (zn)<BR>                                                               (while (= (rem (+ pt_online_num edge_int_num) 2) 1)<BR>                                                               (command "circle" p0 1 "" )<BR>                                                               (setq x (- x 10))       <BR>                                                               (setq p0 (list x y))<BR>                                                                                                                                       )


               (setq y (+ y 10))       <BR>               (setq p0 (list x y))<BR>               (command "circle" p0 1 "" )<BR>               )<BR>       (while (= (rem (+ pt_online_num edge_int_num) 2) 1)<BR>                                                               (zn)<BR>                                                               (while (= (rem (+ pt_online_num edge_int_num) 2) 1)<BR>                                                               (command "circle" p0 1 "" )<BR>                                                               (setq x (- x 10))       <BR>                                                               (setq p0 (list x y))<BR>                                                                                                                                       )


               (setq y (- y 10))       <BR>               (setq p0 (list x y))<BR>               (command "circle" p0 1 "" )<BR>               )


)



<BR><BR>

meflying 发表于 2004-6-10 10:50:00

注意:        edge_int_num                                       pt_online_num这两个变量是zn函数的局部变量,离开这个函数后,这个变量就不存在了,所以你主函数的同样名字的两个变量跟ZN函数里这两个变量是没有关系的,这样就导致主函数中的变量没有赋值。。。


另:(setq X_lst (mapcar 'car plendpt));这里这样就可以了
页: [1]
查看完整版本: [LISP]请帮我的程序指出错误