tryhi 发表于 2015-3-13 15:50:45

如何获得元素的矩形范围

本帖最后由 tryhi 于 2015-3-13 15:52 编辑




红色的图形是元素,虚线框是为了便于理解画出来,如何取得它的矩形范围,就是说如何取得左下角跟右上角的坐标

mingjing9971 发表于 2015-3-13 15:50:46

;实体包围盒
(defun Getbox (obj / bp up)
(vla-getboundingbox obj 'bp 'up)
(setq bp (safearray-value bp)
up (safearray-value up)
)
(list bp
(list (car up) (cadr bp) 0.)
up
(list (car bp) (cadr up) 0.)
)
)
;;通过直线的平面
(defun GetPlan (p1 p2 / an)
(setq an (angle p1 p2))
(cond
    ((equal an 0. 1e-8)
   (list p1 '(0. 1. 0.))
    )
    ((equal an (/ pi 2) 1e-8)
   (list p1 '(-1. 0. 0.))
    )
    ((equal an pi 1e-8)
   (list p1 '(0. -1. 0.))
    )
    (t (list p1 '(1. 0. 0.)))
)
)
;;
(defun getclosestpt (curve lst)
(vlax-curve-getclosestpointtoprojection
    curve
    (car lst)
    (cadr lst)
    t
)
)
;;点集包围盒
(defun pnts:box (pts / xpt ypt xmin xmax ymin ymax)
(setq xpt(mapcar 'car pts)
ypt(mapcar 'cadr pts)
xmin (apply 'min xpt)
xmax (apply 'max xpt)
ymin (apply 'min ypt)
ymax (apply 'max ypt)
)
(list (list xmin ymin 0.)
(list xmax ymin 0.)
(list xmax ymax 0.)
(list xmin ymax 0.)
)
)
(defun c:tt (/ e obj box pts)
(setq e (car (entsel "\nPick Spline: ")))
(setq obj (vlax-ename->vla-object e))
(setq box (Getbox obj))
(setq pts (mapcar '(lambda (p1 p2)
         (getclosestpt obj (getplan p1 p2))
       )
      box
      (cdr (reverse (cons (car box) (reverse box))))
   )
)
(entmakex
    (append '((0 . "LWPOLYLINE")
       (100 . "AcDbEntity")
       (100 . "AcDbPolyline")
       (90 . 4)
       (70 . 1)
      )
   (mapcar
       '(lambda (x) (cons 10 (list (car x) (cadr x))))
       (pnts:box pts)
   )
    )
)
)转发自晓东论坛

自贡黄明儒 发表于 2015-3-13 16:25:02

http://bbs.mjtd.com/forum.php?mod=viewthread&tid=81308&extra=page%3D1%26filter%3Dtypeid%26typeid%3D108%26typeid%3D108

lr2012 发表于 2015-3-15 13:58:42

可以用这个插件实现最小包围,你试试

yizhi4669 发表于 2017-8-13 11:03:19


谢谢分享!!!

LIULISHENG 发表于 2020-3-1 19:54:35

学习了学习了

chwnin 发表于 2020-3-2 19:44:27

学习一下。

广厦千万 发表于 2020-3-3 07:35:35


谢谢分享!!!

zmzk 发表于 2022-1-29 19:04:03

收入囊中,有用啊

fcan 发表于 2022-5-12 19:43:05

谢谢!收入备用:loveliness:
页: [1]
查看完整版本: 如何获得元素的矩形范围