Abrasive Posted March 17, 2023 Posted March 17, 2023 Has anyone written a routine that draws a simp le right triangle, given the base and degree? in the attached drawing, I would like to enter 4" then 30degrees and have the triangle drawn. If possible I could then place it using the mouse? Thank you in advance! Quote
marko_ribar Posted March 17, 2023 Posted March 17, 2023 (defun c:triang ( / d a p p1 p2 ) (and (not (initget 7)) (setq d (getdist "\nPick or specify base dimension : ")) (not (initget 7)) (setq a (getreal "\nSpecify angle on base point in decimal degrees : ")) (not (initget 1)) (setq p (getpoint "\nPick base point : ")) (setq p1 (polar p 0.0 d)) (setq p2 (inters p1 (polar p1 (* 0.5 pi) 1.0) p (polar p (cvunit a "degree" "radian") 1.0) nil)) (entmake (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 3) (cons 70 (1+ (* 128 (getvar (quote plinegen))))) (cons 38 0.0) (cons 10 p) (cons 10 p1) (cons 10 p2) (cons 210 (list 0.0 0.0 1.0)) ) ) ) (princ) ) 1 Quote
Abrasive Posted March 17, 2023 Author Posted March 17, 2023 hmmm...Error: Invalid parameter. looks like its going to do exactly what I need. I'm not sure where it throws the error but it happens when it asks me to place the tringle? Quote
Steven P Posted March 17, 2023 Posted March 17, 2023 as an alternative using traditional trigonometry for fun to get the 3 points since it is a right angle triangle (defun tan (num) (setq num (cvunit num "degree" "radian")) (/ (sin num)(cos num)) ) (setq d (getdist "Get Distance")) (setq a (getreal "Get Angle")) (setq P1 (getpoint "Get insert Point")) (setq P2 (mapcar '+ (list d 0 0) P1)) (setq P3 (mapcar '+ (list 0 (* d (tan a)) 0) P2)) then do the entmake as above Quote
Abrasive Posted March 17, 2023 Author Posted March 17, 2023 I like using trig instead, I can read it better, but I'm still getting an error. (defun tan (num) (setq num (cvunit num "degree" "radian")) (/ (sin num)(cos num)) ) (defun c:triang ( / d a p p1 p2 p3) (and (not (initget 7)) (setq d (getdist "Get Distance")) (setq a (getreal "Get Angle")) (setq P1 (getpoint "Get insert Point")) (setq P2 (mapcar '+ (list d 0 0) P1)) (setq P3 (mapcar '+ (list 0 (* d (tan a)) 0) P2)) (entmake (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 3) (cons 70 (1+ (* 128 (getvar (quote plinegen))))) (cons 38 0.0) (cons 10 p1) (cons 10 p2) (cons 10 p3) (cons 210 (list 0.0 0.0 1.0)) ) ) ) (princ) ) That is what I have, but it throws "Error: Invalid parameter." I must be missing something Quote
ronjonp Posted March 17, 2023 Posted March 17, 2023 28 minutes ago, Abrasive said: I like using trig instead, I can read it better, but I'm still getting an error. (defun tan (num) (setq num (cvunit num "degree" "radian")) (/ (sin num)(cos num)) ) (defun c:triang ( / d a p p1 p2 p3) (and (not (initget 7)) (setq d (getdist "Get Distance")) (setq a (getreal "Get Angle")) (setq P1 (getpoint "Get insert Point")) (setq P2 (mapcar '+ (list d 0 0) P1)) (setq P3 (mapcar '+ (list 0 (* d (tan a)) 0) P2)) (entmake (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 3) (cons 70 (1+ (* 128 (getvar (quote plinegen))))) (cons 38 0.0) (cons 10 p1) (cons 10 p2) (cons 10 p3) (cons 210 (list 0.0 0.0 1.0)) ) ) ) (princ) ) That is what I have, but it throws "Error: Invalid parameter." I must be missing something Works here: 1 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.