本帖最后由 Gu_xl 于 2012-7-17 16:03 编辑
highflybir 发表于 2012-7-17 09:46
现在更新了程序。比以前的快了十倍。
同时附上国外的一个好方法。
命令是:test.
ElpanovEvgeniy 的方法稍加改进,剔除重点,即不出现最小距离为零的情况!
- ;|***************************************************************************************
- by ElpanovEvgeniy
- last edit 08.01.2012
- the library function
- find a pair of points with the smallest distance between them
- -----------------------------------------------------------------------------------------
- argument - list points
- returne - list pair points
- ***************************************************************************************|;
- (defun eea-cpp (PtSet / MiniD F Pairs)
- (defun f (1stPt Pairs PtSet / dist)
- (while (and PtSet
- (equal (car 1stPt) (caar PtSet) MiniD)
- )
- (setq Pairs
- (cond
- ((equal (setq dist (distance 1stPt (car PtSet)))
- MiniD
- 1e-8)
- (cons (list 1stPt (car PtSet)) Pairs)
- )
- ((and (< dist MiniD) (not (equal dist 0 1e-8))) ;_ 过滤重点情况
- (setq MiniD dist)
- (list (list 1stPt (car PtSet)))
- )
- (Pairs)
- )
- PtSet (cdr PtSet)
- )
- )
- Pairs
- )
- (setq PtSet (vl-sort PtSet
- (function (lambda (e1 e2) (<= (car e1) (car e2)))))
- Pairs nil
- )
- ;;计算初始MiniD,确保不为零
- (vl-some
- '(lambda (a)
- (not (equal (setq MiniD (distance (car PtSet) a)) 0 1e-8)))
- (cdr ptset)
- )
- (foreach a PtSet
- (setq Pairs (f (car PtSet) Pairs (cdr PtSet))
- PtSet (cdr PtSet)
- )
- )
- Pairs
- )
|