- UID
- 729558
- 积分
- 1966
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2014-4-13
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2016-11-1 11:20:00
|
显示全部楼层
本帖最后由 aimisiyou 于 2016-11-1 12:33 编辑
;;;函数为(clfun (getpoint) n m a b (list 0 nil))
;;;由于递归运行,对于部分(n,m)数据会出现结果异常或栈溢出、访问异常错误情况
;;目前检测正常的数据为(n,1) ,(n,2)、(4,3)、(3+4n,3)、(nk,k)形式的(n,m) (其中n>=m)
;;;(n,m)=(5,3)时能运行,但结果不正确不知什么情况,看来递归运算出错率很高
(defun drawone(pt a b flag tfx)
(if flag
(entmake
(list
'(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(90 . 4)
'(70 . 1)
(cons 10 (list (car pt) (cadr pt)))
(cons 10 (list (+ (car pt) a) (cadr pt) ))
(cons 10 (list (+ (car pt) a) (+ (cadr pt) (* b tfx)) ))
(cons 10 (list (car pt) (+ (cadr pt) (* b tfx)) ) )
)
)
(entmake
(list
'(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(90 . 4)
'(70 . 1)
(cons 10 (list (car pt) (cadr pt)))
(cons 10 (list (+ (car pt) b) (cadr pt) ))
(cons 10 (list (+ (car pt) b) (+ (cadr pt) (* a tfx)) ))
(cons 10 (list (car pt) (+ (cadr pt) (* a tfx)) ) )
)
)
)
)
(defun f(pt n a b tfx)
(if (= n 1)
(drawone pt a b t tfx)
(progn
(f pt 1 a b tfx)
(setq i 1)
(while (< i n)
(setq pt1 (list (car pt) (+ (cadr pt) (* tfx (+ b (* a i) (* a -1))))))
(setq pt2 (list (+ (car pt) (- a b) (* i b)) (cadr pt) ))
(drawone pt1 a b nil tfx)
(drawone pt2 a b nil tfx)
(setq i (+ i 1))
)
(f (list (+ (car pt) b) (+ (cadr pt) (* a tfx))) (- n 1) a b tfx)
)
)
)
(defun det (n m)
(setq n1 (/ (+ n 1) 2) n2 (/ n 2) m1 (/ (+ m 1) 2) m2 (/ m 2))
(setq va (list (list n1 m1) (list n2 m2) (list (- n1 n2) (- m1 m2))))
)
(defun vfun (tmin)
(setq i 0 vlst nil)
(while (< i tmin)
(repeat tmin (setq vlst (cons i vlst)))
(setq i (+ i 1))
)
vlst
)
(defun hfun (tmin)
(setq j 0 lst nil hlst nil)
(while (< j tmin)
(setq lst (cons j lst))
(setq j (+ j 1))
)
(repeat tmin (setq hlst (append lst hlst)))
hlst
)
(defun clfun (pt n m a b lst)
(if (= m 1)
(if (= (car lst) 0)
(progn
(if (member '(0 1) (cdr lst))
(f pt (+ n 1) a b 1)
(f (list (car pt) (+ (cadr pt) (+ (* n a) b))) (+ n 1) a b -1)
)
)
(progn
(if (member '(0 1) (cdr lst))
(f (list (car pt) (+ (cadr pt) (+ (* n a) b))) (+ n 1) a b -1)
(f pt (+ n 1) a b 1)
)
)
)
(if (> (setq tmin (gcd n m)) 1)
(mapcar '(lambda (i j) (clfun (list (+ (car pt)(* i (+ (* a (/ m tmin)) (* b (/ n tmin))))) (+ (cadr pt) (* j (+ (* a (/ n tmin)) (* b (/ m tmin))))))(/ n
tmin) (/ m tmin) a b lst) ) (vfun tmin) (hfun tmin))
(progn
(if (= (car lst) 0)
(cond
((equal (cdr lst) (list nil))
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)) )
(clfun pt nd md a b (cons 0 (list (caddr (det n m)))))
(clfun (polar pt 0 (+ (* a md) (* b nd)) ) nx mx a b (cons 1 (list nil)))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (list nil)))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx)))(+ (cadr pt)(+ (* a nx) (* b mx)))) nd md a b (cons 0 (list (caddr (det n m)))))
)
)
((equal (car (cdr lst)) (list 1 1))
(if (and (= (- n m) 1) (= (rem m 2) 0))
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nx mx a b (cons 0 (cdr lst)))
(clfun (polar pt 0 (+ (* a mx) (* b nx)) ) nd md a b (cons 1 (list (caddr (det n m)))))
(clfun (polar pt (/ pi 2) (+ (* a nx) (* b mx))) nd md a b (cons 1 (list (caddr (det n m)))))
(clfun (list (+ (car pt) (+ (* a md) (* b nd)))(+ (cadr pt) (+ (* a nd) (* b md)))) nx mx a b (cons 0 (cdr lst)))
)
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nd md a b (cons 0 (cons (caddr (det n m)) (cdr lst))))
(clfun (polar pt 0 (+ (* a md) (* b nd)) ) nx mx a b (cons 1 (list nil)))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (list nil)))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx)))(+ (cadr pt) (+ (* a nx) (* b mx)))) nd md a b (cons 0 (cons (caddr (det n m)) (cdr lst))))
)
)
)
((equal (car (cdr lst)) (list 1 0))
(if (equal (caddr (det n m)) (list 1 0) )
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nd md a b (cons 0 (cons (caddr (det n m)) (cdr lst))))
(clfun (polar pt 0 (+ (* a md) (* b nd)) ) nx mx a b (cons 1 (list nil)))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (list nil)))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx))) (+ (cadr pt) (+ (* a nx) (* b mx))) ) nd md a b (cons 0 (cons (caddr (det n m)) (cdr
lst))))
)
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nd md a b (cons 0 (cdr lst)))
(clfun (polar pt 0 (+ (* a md) (* b nd)) ) nx mx a b (cons 1 (list (caddr (det n m)))))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (list (caddr (det n m)))))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx))) (+ (cadr pt) (+ (* a nx) (* b mx)))) nd md a b (cons 0 (cdr lst)))
)
)
)
((equal (car (cdr lst)) (list 0 1))
(if (equal (caddr (det n m)) (list 0 1))
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nd md a b (cons 0 (cons (caddr (det n m)) (cdr lst))))
(clfun (polar pt 0 (+ (* a md) (* b nd))) nx mx a b (cons 1 (list nil)))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (list nil)))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx))) (+ (cadr pt) (+ (* a nx) (* b mx))) ) nd md a b (cons 0 (cons (caddr (det n m))
(cdr lst))))
)
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nx mx a b lst)
(clfun (polar pt 0 (+ (* a mx) (* b nx)) ) nd md a b (cons 1 (list (caddr (det n m)))))
(clfun (polar pt (/ pi 2) (+ (* a nx) (* b mx))) nd md a b (cons 1 (list (caddr (det n m)))))
(clfun (list (+ (car pt) (+ (* a md) (* b nd))) (+ (cadr pt) (+ (* a nd) (* b md)))) nx mx a b lst)
)
)
)
)
(cond
((equal (cdr lst) (list nil))
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nd md a b (cons 0 (list (caddr (det n m)))))
(clfun (polar pt 0 (+ (* a md) (* b nd)) ) nx mx a b (cons 1 (list nil)))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (list nil)))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx))) (+ (cadr pt) (+ (* a nx) (* b mx))) ) nd md a b (cons 0 (list (caddr (det n m)))))
)
)
( (equal (car (cdr lst)) (list 1 1))
(if (and (= (- n m) 1) (= (rem m 2) 0))
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr
dlst)))
(clfun pt nd md a b (cons 0 (list (caddr (det n m)))))
(clfun (polar pt 0 (+ (* a md) (* b nd)) ) nx mx a b (cons 1 (cdr lst)))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (cdr lst)))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx))) (+ (cadr pt) (+ (* a nx) (* b mx)))) nd md a b (cons 0 (list (caddr (det n m)))))
)
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr
dlst)))
(clfun pt nx mx a b (cons 0 (list nil)))
(clfun (polar pt 0 (+ (* a mx) (* b nx)) ) nd md a b (cons 1 (cons (caddr (det n m)) (cdr lst))))
(clfun (polar pt (/ pi 2) (+ (* a nx) (* b mx))) nd md a b (cons 1 (cons (caddr (det n m)) (cdr lst))))
(clfun (list (+ (car pt) (+ (* a md) (* b nd))) (+ (cadr pt) (+ (* a nd) (* b md)))) nd md a b (cons 0 (list nil)))
)
)
)
( (equal (car (cdr lst)) (list 1 0))
(if (equal (caddr (det n m)) (list 1 0) )
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nx mx a b (cons 0 (list nil)))
(clfun (polar pt 0 (+ (* a mx) (* b nx)) ) nd md a b (cons 1 (cons (caddr (det n m)) (cdr lst))))
(clfun (polar pt (/ pi 2) (+ (* a nx) (* b mx))) nd md a b (cons 1 (cons (caddr (det n m)) (cdr lst))))
(clfun (list (+ (car pt) (+ (* a md) (* b nd))) (+ (cadr pt) (+ (* a nd) (* b md))) ) nx mx a b (cons 0 (list nil)))
)
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nd md a b (cons 0 (list (caddr (det n m)))))
(clfun (polar pt 0 (+ (* a md) (* b nd)) ) nx mx a b (cons 1 (cdr lst)))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (cdr lst)))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx))) (+ (cadr pt) (+ (* a nx) (* b mx)))) nd md a b (cons 0 (list (caddr (det n m)))))
)
)
)
( (equal (car (cdr lst)) (list 0 1))
(if (equal (caddr (det n m)) (list 0 1))
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nx mx a b (cons 0 (list nil)))
(clfun (polar pt 0 (+ (* a mx) (* b nx)) ) nd md a b (cons 1 (cons (caddr (det n m)) (cdr lst))))
(clfun (polar pt (/ pi 2) (+ (* a nx) (* b mx))) nd md a b (cons 1 (cons (caddr (det n m)) (cdr
lst))))
(clfun (list (+ (car pt) (+ (* a md) (* b nd))) (+ (cadr pt) (+ (* a nd) (* b md)))) nx mx a b (cons 0 (list nil)))
)
(progn
(setq dlst (det n m) nd (car (car dlst)) md (cadr (car dlst)) nx (car (cadr dlst)) mx (cadr (cadr dlst)))
(clfun pt nd md a b (cons 0 (list (caddr (det n m)))))
(clfun (polar pt 0 (+ (* a md) (* b nd)) ) nx mx a b (cons 1 (cdr lst)))
(clfun (polar pt (/ pi 2) (+ (* a nd) (* b md))) nx mx a b (cons 1 (cdr lst)))
(clfun (list (+ (car pt) (+ (* a mx) (* b nx))) (+ (cadr pt) (+ (* a nx) (* b mx)))) nd md a b (cons 0 (list (caddr (det n m)))))
)
)
)
)
)
)
)
)
)
(clfun (getpoint) 4 3 10 6 (list 0 nil))
|
|