您好,我编写了这段代码,它在多段线(具有多个顶点)的内部或外部绘制三角形,但根据缩放级别,它会给出越来越好/越差的结果(缩放越大,效果越好)。我所说的缩放级别是这样的,当多段线占据整个屏幕时,它确实会工作,但会出现一些错误,如果减少缩放,则它不会工作,而当增加缩放时,它会工作得很好。这可能取决于三角形(用户输入)与缩放级别的相对大小。有没有办法纠正这种行为?
- (defun c:vert (/ obj1 oft wid spa ip obj2 len l1 l2 sp pt1 pt2 ptm slopeP slopeM ptt1 ptt2 pttR pttL ptt pss it)
- (vl-load-com)
- (setq
- obj1 (ssget C)
- oft (float (getreal "Triangle height: "))
- wid (float (getreal "Triangle width: "))
- spa (float (getreal "Distance between triangles: "))
- )
- (setq ip (strcase (getstring "R(ight) or L(eft): ")))
- (setq
- obj2 (vlax-ename->vla-object (ssname obj1 0))
- len (vlax-get-property obj2 "length")
- l1 (float 0)
- l2 (float wid)
- )
- (while (< l1 len)
- (setq
- sp (vlax-curve-getPointAtDist obj2 0)
- pt1 (vlax-curve-getPointAtDist obj2 l1)
- pt2 (vlax-curve-getPointAtDist obj2 l2)
- ptm (vlax-curve-getPointAtDist obj2 (/ (+ l1 l2) 2))
- slopeP (+ (if (= (car pt2) (car pt1)) (/ pi 2) (atan (/ (- (nth 1 pt2) (nth 1 pt1)) (- (nth 0 pt2) (nth 0 pt1))))) (/ pi 2))
- slopeM (- (if (= (car pt2) (car pt1)) (/ pi 2) (atan (/ (- (nth 1 pt2) (nth 1 pt1)) (- (nth 0 pt2) (nth 0 pt1))))) (/ pi 2))
- ptt1 (list (+ (nth 0 ptm) (* oft (cos slopeP))) (+ (nth 1 ptm) (* oft (sin slopeP))))
- ptt2 (list (+ (nth 0 ptm) (* oft (cos slopeM))) (+ (nth 1 ptm) (* oft (sin slopeM))))
- pttR (if (< (- (* (- (nth 0 pt2) (nth 0 pt1)) (- (nth 1 ptt1) (nth 1 pt1))) (* (- (nth 0 ptt1) (nth 0 pt1)) (- (nth 1 pt2) (nth 1 pt1)))) 0) ptt1 ptt2)
- pttL (if (> (- (* (- (nth 0 pt2) (nth 0 pt1)) (- (nth 1 ptt1) (nth 1 pt1))) (* (- (nth 0 ptt1) (nth 0 pt1)) (- (nth 1 pt2) (nth 1 pt1)))) 0) ptt1 ptt2)
- ptt (if (= ip "R") pttR pttL)
- )
- (command "_.pline" pt1 ptt pt2 "")
- (setq
- l1 (float (+ l1 wid spa))
- l2 (float (+ l2 spa wid))
- )
- )
- )
|