本帖最后由 Gu_xl 于 2015-8-20 13:40 编辑
因为G版的函数库有点大,而且对cad版本的版本有要求,我自编的一个小程序功能比较简单,根据G版提供程序的思路,我做了一个转换用户坐标系再排序的程序,但是测试中困难重重,请再帮我看看问题出在什么地方,不胜感激- ;输入原始点,原始点排序,第一第二个点决定用户坐标系的原点及x轴方向
- (defun c:tt ()
- (setq lst (append (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint)) (list (getpoint))))
- (setq p1 (car lst))
- (setq p2 (car (cdr lst)))
- ;;点自上而下,自左而右排序
- (setq lst1 (vl-sort lst '(lambda (a b) (if (equal (cadr a)(cadr b) 1e-3)(< (car a) (car b)) (> (cadr a)(cadr b))))))
- ;;点自左而右 自上而下排序
- (setq lst2 (vl-sort lst '(lambda (a b) (if (equal (car a)(car b) 1e-3)(> (cadr a) (cadr b)) (< (car a)(car b))))))
-
- )
- ;做连线
- (defun c:bb1 ()
- (setq lsttemp lst1)
- (repeat (- (length lsttemp) 1)
- (progn
- (setq p3 (car lsttemp))
- (setq p4 (car (cdr lsttemp)))
- (command "line" p3 p4 "")
- (setq lsttemp (cdr lsttemp))
- )
- )
- )
- (defun c:bb2 ()
- (setq lsttemp2 lst2)
- (repeat (- (length lsttemp2) 1)
- (progn
- (setq p3 (car lsttemp2))
- (setq p4 (car (cdr lsttemp2)))
- (command "line" p3 p4 "")
- (setq lsttemp (cdr lsttemp2))
- )
- )
- )
- ;转坐标系排序
- (defun c:zz ()
- (command "ucs" "w")
- (command "ucs" p1 p2 "")
- (setq lstzz '())
- (setq lsttemp3 lst)
- ;lstzz为转系后的坐标
- (repeat (length lsttemp3)
- (setq pt3 (trans (car lsttemp3) 0 1))
- (setq lsttemp3 (cdr lsttemp3))
- (setq lstzz (cons pt3 lstzz))
- )
- ;;点自上而下,自左而右排序
- (setq lst1 (vl-sort lstzz '(lambda (a b) (if (equal (cadr a)(cadr b) 1e-3)(< (car a) (car b)) (> (cadr a)(cadr b))))))
- ;;点自左而右 自上而下排序
- (setq lst2 (vl-sort lstzz '(lambda (a b) (if (equal (car a)(car b) 1e-3)(> (cadr a) (cadr b)) (< (car a)(car b))))))
- (command "ucs" "w")
- (setq lsttemp3 lstzz)
- (setq lstzz '())
- ;lstzz为排好序后转会坐标系的表
- (repeat (length lsttemp3)
- (setq pt3 (trans (car lsttemp3) 1 0))
- (setq lsttemp3 (cdr lsttemp3))
- (setq lstzz (cons pt3 lstzz))
- )
- )
;bb1是上下排序的连线,bb2是左右排序的连线,生成的线条那叫一个乱啊,排序不成功,单页找不到原因出在哪里 |