Nikon Posted 1 hour ago Posted 1 hour ago (edited) Hello everyone, can you tell me how to get the coordinates of the upper-left point of the trapezoid correctly? And the angle of 30 degrees does not work... (defun c:DrawTrapez30 (/ baseHeight height angle radian topBase pt1 pt2 pt3 pt4) (setq baseHeight (getreal "\nEnter the size of the bottom base: ")) (setq height (getreal "\nEnter the height of the trapezoid: ")) ;; Angle in radians (setq angle 30) (setq radian (* angle (/ pi 180.0))) ;; Calculating the upper base (setq topBase (* baseHeight (cos radian))) ;; Determining the starting point (setq pt1 (getpoint "\nEnter the starting point of the lower base: ")) ;; Calculating the coordinates of the vertices of a trapezoid??? (setq pt2 (list (car pt1) (+ (cadr pt1) height))) ; upper left point (setq pt3 (list (+ (car pt1) baseHeight) (cadr pt1))) ; lower right point (setq pt4 (list (+ (car pt1) baseHeight (* (sin radian) height)) (+ (cadr pt1) height ))) ; upper right point ;; Drawing a trapezoid (command "_.pline" pt1 pt2 pt4 pt3 "_C") (princ)) Edited 1 hour ago by Nikon Quote
marko_ribar Posted 16 minutes ago Posted 16 minutes ago Untested, but it should work IMHO... (defun c:DrawTrapez30 (/ baseHeight height angle radian topBase pt1 pt2 pt3 pt4) (initget 7) (setq baseHeight (getreal "\nEnter the size of the bottom base: ")) (initget 7) (setq height (getreal "\nEnter the height of the trapezoid: ")) ;; Angle in radians (setq angle 30) (setq radian (* angle (/ pi 180.0))) ;; Determining the starting point (setq pt1 (mapcar (function +) (list 0.0 0.0) (getpoint "\nEnter the starting point of the lower base: "))) ;; Calculating the coordinates of the vertices of a trapezoid (setq pt2 (polar pt1 0.0 baseHeight)) (setq pt3 (polar pt2 (- (* 0.5 pi) radian) (/ height (cos radian)))) (setq pt4 (polar pt1 (+ (* 0.5 pi) radian) (/ height (cos radian)))) ;; Calculating the upper base (setq topBase (distance pt3 pt4)) ;; Drawing a trapezoid (command "_.pline" pt1 pt2 pt3 pt4 "_C") (princ) ) Quote
GLAVCVS Posted 11 minutes ago Posted 11 minutes ago 1 hour ago, Nikon said: Hello everyone, can you tell me how to get the coordinates of the upper-left point of the trapezoid correctly? And the angle of 30 degrees does not work... (defun c:DrawTrapez30 (/ baseHeight height angle radian topBase pt1 pt2 pt3 pt4) (setq baseHeight (getreal "\nEnter the size of the bottom base: ")) (setq height (getreal "\nEnter the height of the trapezoid: ")) ;; Angle in radians (setq angle 30) (setq radian (* angle (/ pi 180.0))) ;; Calculating the upper base (setq topBase (* baseHeight (cos radian))) ;; Determining the starting point (setq pt1 (getpoint "\nEnter the starting point of the lower base: ")) ;; Calculating the coordinates of the vertices of a trapezoid??? (setq pt2 (list (car pt1) (+ (cadr pt1) height))) ; upper left point (setq pt3 (list (+ (car pt1) baseHeight) (cadr pt1))) ; lower right point (setq pt4 (list (+ (car pt1) baseHeight (* (sin radian) height)) (+ (cadr pt1) height ))) ; upper right point ;; Drawing a trapezoid (command "_.pline" pt1 pt2 pt4 pt3 "_C") (princ)) I think you should rename the variable 'angle': 'angle' is a language symbol, that is, a function. Try changing it to 'ang', for example. Quote
pkenewell Posted 1 minute ago Posted 1 minute ago Here's my quick version: (defun c:trapezoid (/ bw p0 p1 p2 p3 p4 ra sa th) (if (and (setq bw (getreal "\nEnter the width of the Base: ")) (setq th (getreal "\nEnter the Height: ")) (setq sa (getreal "\nEnter the side angles: ")) (setq p0 (getpoint "\nSelect the insertion point: ")) ) (progn (setq ra (* pi (/ sa 180.0)) p1 (list (- (car p0) (/ bw 2)) (cadr p0) (caddr p0)) p2 (list (+ (car p1) bw) (cadr p0) (caddr p0)) p3 (list (+ (car p2) (* (/ th (cos ra)) (sin ra))) (+ (cadr p0) th) (caddr p0)) p4 (list (- (car p1) (* (/ th (cos ra)) (sin ra))) (+ (cadr p0) th) (caddr p0)) ) (command-s "._pline" "_non" p1 "_non" p2 "_non" p3 "_non" p4 "_c") ) ) ) Quote
Recommended Posts
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.