Sjotroll Posted July 10, 2022 Share Posted July 10, 2022 Hi, I've written this code which draws triangles on the inside or outside of a polyline (with multiple vertexes), but it gives increasingly better/worse results depending on the zoom level (better results are obtained with higher zoom). The zoom levels I'm talking about are such that when the polyline occupies the whole screen it does work with some errors, if you reduce the zoom then it does not work, and when you increase the zoom it works perfectly. It probably depends on the relative size of the triangles (which are user inputs) to the zoom level. Is there a way to correct this behavior? (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)) ) ) ) Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.