669423907 发表于 2013-9-20 21:44
;;----------------=={ Minimum Bounding Box }==----------------;;
;; ...
Lee Mac确实很牛,如果加载highflybir的矩阵,程序如下
- ;;(LM:MinBoundingBox 选择集 精度[取值0~1]);返回包盒四角点
- (defun LM:MinBoundingBox (ss pr / an ba bb bm cn cv i l mb)
- ;;VLA列表的包围盒的最小最大点列表
- (defun LM:ListBoundingBox (lst / l1 l2 ll ur)
- (foreach obj lst
- (vla-getboundingbox obj 'll 'ur)
- (setq l1 (cons (vlax-safearray->list ll) l1)
- l2 (cons (vlax-safearray->list ur) l2)
- )
- )
- (mapcar
- (function (lambda (a b) (apply 'mapcar (cons a b))))
- '(min max)
- (list l1 l2)
- )
- )
- (repeat (setq i (sslength ss))
- (setq l (cons (vla-copy
- (vlax-ename->vla-object (ssname ss (setq i (1- i))))
- )
- l
- )
- )
- )
- (setq bb (LM:ListBoundingBox l)) ;((-1437.59 2366.2 0) (-1429.07 2376.16 0))
- (setq pr (* pr pi)
- cn (apply 'mapcar
- (cons (function (lambda (a b) (/ (+ a b) 2.0))) bb)
- )
- cv (vlax-3D-point cn) ;中点
- bm (* (- (caadr bb) (caar bb)) (- (cadadr bb) (cadar bb))) ;x*y相当于面积
- mb (cons 0.0 bb)
- an 0
- )
- (while (< (setq an (+ an pr)) pi)
- (foreach x l (vla-rotate x cv pr)) ;旋转
- (setq bb (LM:ListBoundingBox l) ;旋转之后图元列表的最小包围盒
- ba (* (- (caadr bb) (caar bb)) (- (cadadr bb) (cadar bb)))
- )
- (if (< ba bm)
- (setq bm ba
- mb (cons an bb)
- )
- )
- )
- (foreach x l (vla-delete x)) ;删除
- (LM:RotateByMatrix
- (mapcar
- (function
- (lambda (a)
- (mapcar (function (lambda (b) ((eval b) (cdr mb)))) a)
- )
- )
- '((caar cadar) (caadr cadar) (caadr cadadr) (caar cadadr))
- )
- cn ;旋转中心点
- (- (car mb)) ;角度
- )
- )
|