找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 530|回复: 0

[教学] 【AcGe几何库应用(三十九)】求曲线的正交包围盒和随轴包围盒

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2018-6-8 19:55:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
使用AcGeEntity3d::boundBlock和AcGeEntity3d::orthoBoundBlock

1、求正交的盒子用 orthoBoundBlock,求随轴的盒子,用boundBlock

2、对于正交的盒子,调用isBox返回kTrue

3、getMinMaxPoints是求正交盒子的最大最小点

4、求随轴盒子的最大最小点,不要用getMinMaxPoints,要考虑转轴的向量和基点,这个通过Get方法得到

5、当然,都通过GET,都能得到盒子的正确的四个角点,下面为了说明区别,求正交的盒子,用的是GetMinMaxPoints

AcGeBoundBlock3d::get Function
void
get(
AcGePoint3d& base,
AcGeVector3d& dir1,
AcGeVector3d& dir2,
AcGeVector3d& dir3) const;
baseOutput origin vertex a corner of the bounding box
dir1Output direction and size for first side of the bounding box
dir2Output direction and size for second side of the bounding box
dir3Output direction and size for third side of the bounding box
Computes a vertex and sides of the bounding block.



上面的DIR不是单位向量,他们的长度是边的长度。

下面代码演示了,看就理解了。


                               
登录/注册后可看大图


  1. (defun c:tt ()
  2.   (if (and (setq e (car (xdrx_entsel
  3.                           "\n拾取一个曲线<退出>:"
  4.                           '((0 . "*LINE,ARC,ELLIPSE,CIRCLE"))
  5.                         )
  6.                    )
  7.            )
  8.            (setq g (xdge::constructor e))
  9.       )
  10.     (progn
  11.       (xdrx_begin)
  12.       (xdrx_initget "1 2")
  13.       (if (setq sel (getint "\n正交(1)/随轴(2)<退出>:"))
  14.         (progn (cond ((= sel 2)
  15.                       (setq box (xdge::getpropertyvalue g "boundblock"))
  16.                       (setq pts1   (xdge::getpropertyvalue box "get")
  17.                             origin (car pts1)
  18.                             xdir   (cadr pts1)
  19.                             ydir   (caddr pts1)
  20.                             zdir   (cadddr pts1)
  21.                       )
  22.                       (setq p1 origin
  23.                             p2 (mapcar '+ p1 xdir)
  24.                             p3 (mapcar '+ p2 ydir)
  25.                             p4 (mapcar '+ p1 ydir)
  26.                       )
  27.                      )
  28.                      (t
  29.                       (setq box (xdge::getpropertyvalue g "orthoboundblock"))
  30.                       (setq pts1 (xdge::getpropertyvalue box "getMinMaxPoints")
  31.                             dir  (mapcar '- (cadr pts1) (car pts1))
  32.                             p1   (car pts1)
  33.                             p2   (mapcar '+ p1 (list (car dir) 0.0 0.0))
  34.                             p3   (cadr pts1)
  35.                             p4   (mapcar '+ p1 (list 0.0 (cadr dir) 0.0))
  36.                       )
  37.                      )
  38.                )
  39.                (xdrx_polyline_make p1 p2 p3 p4 t)
  40.                (xdrx_setpropertyvalue
  41.                  (entlast)
  42.                  "color"
  43.                  sel
  44.                  "constantwidth"
  45.                  10.0
  46.                )
  47.         )
  48.       )
  49.       (xdrx_end)
  50.     )
  51.   )
  52.   (princ)
  53. )


上面的随轴的盒子,也可以说是这个曲线凸包的最小面积盒,下面图,黄色线是凸包边界,红线是最小面积包围盒


                               
登录/注册后可看大图


下面代码求:
  1. (defun c:tt ()
  2.   (if (setq e (car (xdrx_entsel
  3.                      "\n拾取一个曲线<退出>:"
  4.                      '((0 . "*LINE,ARC,ELLIPSE,CIRCLE"))
  5.                    )
  6.               )
  7.       )
  8.     (progn (setq pts  (xdrx_getsamplept e)
  9.                  hull (xdrx_points_ghull pts)
  10.                  pts1 (xdrx_points_minareabox pts)
  11.            )
  12.            (xdrx_polyline_make pts1 t)
  13.            (xdrx_setpropertyvalue
  14.              (entlast)
  15.              "color"
  16.              1
  17.              "constantwidth"
  18.              15.0
  19.            )
  20.            (xdrx_polyline_make hull t)
  21.            (xdrx_setpropertyvalue
  22.              (entlast)
  23.              "color"
  24.              2
  25.              "constantwidth"
  26.              30.0
  27.            )
  28.     )
  29.   )
  30.   (princ)
  31. )



论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-3-29 22:38 , Processed in 0.174401 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表