最初由 sfjlx 发布
[B]非常感谢各位!
我的意思是如何分组,当然排序也是一部分!
比如有100点,有n组y坐标相等,如何把各个点分好组,每组赋值给一个变量,然后返回! [/B]
看看以下如何?

- [FONT=courier new]
- (defun test (pts / lst ylst)
- (setq pts (vl-sort pts '(lambda (e1 e2)
- (if (equal (cadr e1) (cadr e2) 1e-10)
- (> (car e1) (car e2))
- (> (cadr e1) (cadr e2))
- )
- )
- )
- )
- (while (> (length pts) 0)
- (setq lst (cons (setq ylst (th-assoc-y (cadar pts) pts))
- lst
- )
- )
- (setq pts (txt-list-subtract pts ylst))
- )
- lst
- )
- [/FONT]
子函数

- [FONT=courier new]
- (defun th-assoc-y (key alst / i lst)
- (while (setq i (vl-position key (mapcar
- (function cadr)
- alst
- )
- )
- )
- (setq lst (cons (nth i alst) lst))
- (setq alst (txt3-removenth i alst))
- )
- lst
- )
- (defun txt3-removenth (n lst / i) ; 移除列表的第n项
- (setq j -1)
- (vl-remove-if '(lambda (x)
- (= n (setq j (1+ j)))
- ) lst
- )
- )
- (defun txt-list-subtract (lst1 lst2 / lst);两表差集
- (setq lst '())
- (if lst1
- (progn
- (foreach tmp lst1
- (if (not (member tmp lst2))
- (setq lst (cons tmp lst))
- )
- )
- )
- )
- (setq lst (reverse lst))
- lst
- )
- [/FONT]
测试:
命令: !lst
((2074.22 692.04 0.0) (2049.1 1414.48 0.0) (1520.49 1907.55 0.0) (798.047
1882.42 0.0) (304.973 1353.82 0.0) (330.101 631.376 0.0) (858.711 138.302 0.0)
(1581.15 163.43 0.0) (2074.22 692.04 0.0))
命令: (test lst)
(((858.711 138.302 0.0)) ((1581.15 163.43 0.0)) ((330.101 631.376 0.0))
((2074.22 692.04 0.0) (2074.22 692.04 0.0)) ((304.973 1353.82 0.0)) ((2049.1
1414.48 0.0)) ((798.047 1882.42 0.0)) ((1520.49 1907.55 0.0))) |