Jump to content

Recommended Posts

Posted

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!

image.png

Posted
(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)
)

 

  • Like 1
Posted

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?

Posted

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

Posted

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

Posted
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:

image.png.85d3e3048aa12cba4b9c2761098b1bb8.png

  • Like 1
Posted

Works fine here as well.

 

Nice LISP.

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...