Abrasive Posted March 17 Share Posted March 17 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 Link to comment Share on other sites More sharing options...
marko_ribar Posted March 17 Share Posted March 17 (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 Link to comment Share on other sites More sharing options...
Abrasive Posted March 17 Author Share Posted March 17 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 Link to comment Share on other sites More sharing options...
Steven P Posted March 17 Share Posted March 17 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 Link to comment Share on other sites More sharing options...
Abrasive Posted March 17 Author Share Posted March 17 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 Link to comment Share on other sites More sharing options...
ronjonp Posted March 17 Share Posted March 17 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 Link to comment Share on other sites More sharing options...
SLW210 Posted March 20 Share Posted March 20 Works fine here as well. Nice LISP. 1 Quote Link to comment Share on other sites More sharing options...
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.