马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 st788796 于 2014-11-4 13:51 编辑
函数见 http://bbs.xdcad.net/thread-676796-1-1.html
- ;;逆时针凸包点集
- (defun XD::Pnts:MinRectang (pts / _pnt->2d marea ptl tan
- v1 p1 p2 p3 ydir rec lst
- area box v2 i
- )
- (defun _drawbox (pts col /)
- (apply 'xdrx_grdraw
- (cons
- col
- (cons 1
- (list (car pts)
- (mapcar '+ (car pts) (cadr pts))
- (apply 'mapcar (cons '+ pts))
- (mapcar '+ (car pts) (caddr pts))
- (car pts)
- )
- )
- )
- )
- )
- (defun _pnt->2d (p) (list (car p) (cadr p)))
- (if (<= (length pts) 2)
- pts
- (progn
- (setq pts (xdrx_points_gethull pts) ;_2007+
- pts (mapcar '(lambda (x) (_pnt->2d x)) pts)
- marea 1e328
- ptl pts
- tan (/ pi 2)
- v1 (mapcar '- (cadr pts) (car pts))
- i 0
- )
- (while (and
- (> (length ptl) 2)
- (< (xdrx_vector_angle
- v1
- (setq v2 (mapcar '- (cadr ptl) (car ptl)))
- )
- tan
- )
- )
- (setq ydir (xdrx_vector_product
- (xdrx_vector_normalize (xdrx_vector_perpvector v2))
- (abs (xdrx_point_dist2line
- (caddr ptl)
- (car ptl)
- (cadr ptl)
- )
- )
- )
- rec (xdge::constructor "kBoundBlock2d" (car ptl) v2 ydir);_以一个边为 x轴,第三个点构造斜向bound
- )
- (foreach x pts
- (xdge::setpropertyvalue rec "extend" x);_把所有点加入 boundblock,自动扩充
- )
- (setq lst (xdge::getpropertyvalue rec "get");_boundblock 信息,基点、x轴向量、y轴向量
- area (* (xdrx_vector_length (cadr lst));_边长
- (xdrx_vector_length (caddr lst));_边长
- )
- )
- (_drawbox lst (setq i (1+ i)))
- (princ "\nColor ")
- (princ i)
- (princ " Rectang Area = ")
- (princ (rtos area 2 5))
- (if (< area marea)
- (setq marea area
- box lst
- )
- )
- (setq ptl (cdr ptl))
- )
- (xdge::free)
- (list (car box)
- (mapcar '+ (car box) (cadr box))
- (apply 'mapcar (cons '+ box))
- (mapcar '+ (car box) (caddr box))
- )
- )
- )
- )
- (defun c:tt (/ pts)
- (setq
- pts (XD::pnts:minrectang
- (mapcar '(lambda (x) (xdrx_getpropertyvalue x "position"))
- (xdrx_pickset->ents (ssget '((0 . "point"))))
- )
- )
- )
- ;;(apply 'xdrx_polyline_make (cons t pts))
- (princ)
- )
|