本帖最后由 wzg356 于 2014-12-19 00:05 编辑
自己用不上,学习兴趣来了写的
大量数据没测试过 - ;;;点表求最小包围圆,返回圆心、半径
- ;;; by wzg356 于201411216
- ;;; ==================================================================
- (defun ptlst2arc (ptlst / yy-3arc perPt mapcdr ppdl maxdpp p1p2 p1 p2 perlst p3 maxperl minr)
- ;三点求圆弧圆心半径 by wan1314
- (defun yy-3arc (p1 p2 p3 / z1 z2 yxin)
- (setq z1 (mapcar '(lambda (x y)(/ (+ x y) 2.0)) p1 p2)
- z2 (mapcar '(lambda (x y)(/ (+ x y) 2.0)) p1 p3)
- )
- (if
- (setq yxin (inters
- z1 (polar z1 (+ (angle p1 p2)(* pi 0.5)) 10)
- z2 (polar z2 (+ (angle p1 p3)(* pi 0.5)) 10)
- nil
- )
- )
- (list yxin (distance yxin p1))
- )
- )
- ;;;功能: 点到直线的垂足,距离,来自明经贴
- (defun perPt (P p1 p2 / pt)
- (setq pt (polar p (+ (* 0.5 pi) (angle p1 p2)) 10.0))
- (list (setq pt (inters p1 p2 p pt nil)) (distance p pt))
- )
- ;重复对表的0之后元素组成的表进行表达式操作
- ;http://bbs.xdcad.net/forum.php?mod=viewthread&tid=568299
- (defun mapcdr (expr liste / retl)
- (repeat (1- (length liste))
- (setq retl (cons (apply expr (list liste)) retl))
- (setq liste (cdr liste))
- )
- (reverse retl)
- )
- (setq ppdl
- (apply 'append
- (mapcdr
- '(lambda (rest /)
- (mapcar
- '(lambda (car-von-rest /)
- (list(car rest)car-von-rest (distance (car rest)car-von-rest))
- )
- (cdr rest)
- )
- );用mapcdr确保两两组合
- ptlst
- )
- )
- );((list 点 点 距离)...)的表
- (setq maxd
- (apply 'max (setq maxdpp(mapcar '(lambda(x)(caddr x)) ppdl)))
- )
- (setq p1p2 (nth (vl-position maxd maxdpp) ppdl))
- (setq p1 (car p1p2) p2 (cadr p1p2));距离最大的两点
- (setq perlst
- (mapcar '(lambda(p)(cadr(perPt p p1 p2)))ptlst)
- );所有点与距离最大的两点的(垂距.....)
- (setq p3
- (nth
- (vl-position (setq maxperl (apply 'max perlst))perlst)
- ptlst
- )
- );与距离最大的两点垂距最大的点
- (if (> maxperl (setq minr(/ maxd 2)))
- (yy-3arc p1 p2 p3);得到三点圆弧圆心、半径
- (list (mapcar '(lambda (x y)(/ (+ x y) 2.0)) p1 p2)
- minr
- );最大距离两点为直径的圆心、半径
- )
- )
- ;;测试
- (defun c:tt2 ( / plst arcptr)
- (setq ptlst (list (list 12 0 0)(list 12 13 0)(list 16 19 0)(list 28 9 0)(list 17 4 0)(list 9 12 0)))
- (command "pline" (foreach pt ptlst (command pt)))
- (setq arcptr(ptlst2arc ptlst))
- (command "circle" (car arcptr) (cadr arcptr))
- )
|