求CAD一组串联的直线和圆弧,偏移后的坐标点,如图,求第三种情况的坐标点,如有计算方法请联系我,超级感谢!
4条回答 默认 最新
- 小逸2023 2023-04-02 14:11关注该回答引用ChatGPT
本题需要使用CAD的API来完成。
偏移一个平面线段可以使用CAD的 `offset()` 函数来实现,该函数有两个关键参数:偏移距离和偏移方向。
在获取偏移方向时,我们需要先判断偏移线段的方向,根据向量叉积的规则,如果偏移线段的方向为逆时针,则其法向量方向为指向线段左侧,反之则为指向线段右侧。然后再获取与偏移线段相交的原线段的方向,同样应用向量叉积的规则,如果原线段的方向与偏移线段的方向相同,则其法向量为指向原线段右侧,反之则为指向原线段左侧。
接下来就是将求出的偏移距离乘以偏移方向和法向量来得到偏移后的坐标点。具体实现如下所示。
(defun c:offset ()
(setq offset-distance 10)
(setq old-ents (ssget))
(setq new-ents (ssadd))
(repeat (sslength old-ents))
(setq old-ent (ssname old-ents 0))
(setq ss (ssadd (entget old-ent) new-ents))
(setq type (cdr (assoc 0 (entget old-ent))))
(if (or (eq type "LINE")
(eq type "ARC"))
(progn
(setq start-point (cdr (assoc 10 (entget old-ent))))
(setq end-point (cdr (assoc 11 (entget old-ent))))
(setq direction (mapcar '- end-point start-point))
(setq len (distance start-point end-point))
(if (eq type "ARC")
(progn
(setq center (cdr (assoc 10 (entget old-ent))))
(setq orientation (cdr (assoc 51 (entget old-ent))))
(if (> (car direction) 0)
(setq offset-direction (if (> orientation 0) (cons -1 0) (cons 1 0)))
(setq offset-direction (if (> orientation 0) (cons 1 0) (cons -1 0))))
(if (> orientation 0)
(setq normal-direction (if (> (car direction) 0) (cons 0 -1) (cons 0 1)))
(setq normal-direction (if (> (car direction) 0) (cons 0 1) (cons 0 -1))))
(setq radius (cdr (assoc 40 (entget old-ent))))
(setq angle (cdr (assoc 51 (entget old-ent))))
(setq off-angle (/ (* offset-distance 180) (* radius pi)))
(if (> angle 0)
(setq offset-angle (+ angle off-angle))
(setq offset-angle (- angle off-angle)))
(if (> radius 0)
(progn
(setq offset-start-point (polar center (+ angle off-angle) (- radius offset-distance)))
(setq offset-end-point (polar center (+ offset-angle angle) (- radius offset-distance)))
(if (< offset-angle 0)
(setq offset-angle (+ offset-angle 360)))
(command "arc" offset-start-point center offset-end-point)
)
)
)
(progn
(if (> (car direction) 0)
(setq offset-direction (cons 1 0))
(setq offset-direction (cons -1 0)))
(if (> (car direction) 0)
(setq normal-direction (cons 0 -1))
(setq normal-direction (cons 0 1)))
(setq offset-start-point (mapcar '+ start-point (mapcar '* offset-direction offset-distance)))
(setq offset-end-point (mapcar '+ end-point (mapcar '* offset-direction offset-distance)))
(command "line" offset-start-point offset-end-point)
)
)
)
)
(setq old-ents (ssdel old-ent old-ents))
)
)
该函数首先从选中的实体中提取出线段和圆弧,并在新的选择集中添加偏移后的实体。对于每个线段和圆弧,先判断其方向并计算偏移方向和法向量,然后根据不同的类型进行偏移。对于圆弧,需要根据旋转角度和半径等参数进行处理。最后,继续处理下一个实体,直到所有实体处理完毕。解决 1无用 1
悬赏问题
- ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
- ¥15 安装quartus II18.1时弹出此error,怎么解决?
- ¥15 keil官网下载psn序列号在哪
- ¥15 想用adb命令做一个通话软件,播放录音
- ¥30 Pytorch深度学习服务器跑不通问题解决?
- ¥15 部分客户订单定位有误的问题
- ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
- ¥15 Bug traq 数据包 大概什么价
- ¥15 在anaconda上pytorch和paddle paddle下载报错
- ¥25 自动填写QQ腾讯文档收集表