本帖最后由 springwillow 于 2017-12-1 08:49 编辑
欢迎试用,简单写了一下,加了一些注释,方便同学们参考 - (defun c:getmap()
- (setq dist (getdist "输入垂直距离:"))
- (setq ename (car (entsel)))
- (setq curve (vlax-ename->vla-object ename))
- (setq len (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve)));求多段线长度
- (setq d (/ len 2))
- (setq midpoint (vlax-curve-getPointAtDist curve d));求多段线中点
- (setq param (vlax-curve-getparamatpoint curve midpoint));求中点处的参数,参数的意义为计算点在polyline顶点上的顺序位置值,该值整数为计算点在polyline上的顶点顺序,以0为计数起点,小数部分为计算点在该poly片段上的长度比率
- (setq SecondDeriv (vlax-curve-getSecondDeriv curve param));求中点的法线向量
- (if (equal SecondDeriv '(0 0 0));如果法线的向量为'(0 0 0)说明此线段为直线段,否则为有凸度段
- (progn
- (setq FirstDeriv (vlax-curve-getFirstDeriv curve param));求中点的切线向量
- (setq ang (+ (angle '(0 0 0) FirstDeriv) (* 0.5 pi)));根据切线向量求法向角度
- )
- (setq ang (angle '(0 0 0) SecondDeriv));直接用法线向量求角度
- )
- (setq pt (polar midpoint ang dist))
- (entmake (list '(0 . "LINE") (cons 10 midpoint) (cons 11 pt)))
- )
|