Create isosceles triangle

Create isosceles triangle

carlos_m_gil_p
Advocate Advocate
3,045 Views
13 Replies
Message 1 of 14

Create isosceles triangle

carlos_m_gil_p
Advocate
Advocate

Hello boys.
Could you help me with a lisp, to create an isosceles triangle.
I have a base line that would be the base of the triangle.
And I have a line where the third vertex of the triangle has to pass.
But I need to draw two sides of the triangle that are equal.

I am attaching a dwg file so that you can understand me better.
The cyan lines are what I need to draw, (in the example they are not the same, because I could not make them remain the same in the drawing)

Beforehand thank you very much.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
Accepted solutions (3)
3,046 Views
13 Replies
Replies (13)
Message 2 of 14

hak_vz
Advisor
Advisor

Command POLYGON (POL) in edge mode with three sides creates perfect isosceles triangle 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 14

john.uhden
Mentor
Mentor

1.  Draw a vertical line the length of the triangle height.

2.  Offset the line half of the base length, once to the left and once to the right.

3.  Draw a polyline from endpoint to endpoint to endpoint and close.

4.  Erase the lines.

John F. Uhden

0 Likes
Message 4 of 14

john.uhden
Mentor
Mentor

@hak_vz 

Yes, isosceles, but specifically equilateral.

John F. Uhden

0 Likes
Message 5 of 14

carlos_m_gil_p
Advocate
Advocate

Hi brother.
With the POL command it doesn't work.
The POL command makes equilateral triangles and I need isosceles.
The isosceles triangle has two equal sides and one unequal side.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
Message 6 of 14

hak_vz
Advisor
Advisor

Ok working on code

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this [in simplest terms, minimally tested]:

 

(defun C:WHATEVER (/ basesel base base1 base2 basemid peak)
  (setq
    basesel (entsel "\nTriangle base line: ")
    base (car basesel)
    base1 (vlax-curve-getStartPoint base)
    base2 (vlax-curve-getEndPoint base)
    basemid (osnap (cadr basesel) "_mid")
    peak (car (entsel "\nLine that peak must meet: "))
  )
  (command "_.line"
    "_non" basemid
    (polar basemid (+ (angle base1 base2) (/ pi 2)) 1)
    ""
  ); command
  (setq mid (entlast))
  (command "_.line"
    base1
    (inters
      (vlax-curve-getStartPoint peak) (vlax-curve-getEndPoint peak)
      (vlax-curve-getStartPoint mid) (vlax-curve-getEndPoint mid)
      nil
    ); inters
    base2
    ""
  ); command
  (entdel mid)
  (princ)
)

 

Kent Cooper, AIA
0 Likes
Message 8 of 14

hak_vz
Advisor
Advisor
Accepted solution

 

(defun c:iso_triangle (/ getintersections adoc e c eo co p1 p2 p3 l lo)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 1)
		(princ)
	)
	(defun getintersections	(obj1 obj2 / var)
		(setq var (vlax-variant-value (vla-intersectwith obj1 obj2 1)))
		(if (< 0 (vlax-safearray-get-u-bound var acExtendThisEntity))
		(vlax-safearray->list var)
		) 
	) 
	(setq adoc (vla-get-ActiveDocument (vlax-get-acad-object)) blocks (vla-get-blocks adoc))
	(setq e (car (entsel "\nSelect triangle baseline >")))
	(setq c (car (entsel "\nSelect line where third points lie >")))
	(cond
		((and e c)
				(vla-endundomark adoc)
			(vla-startundomark adoc)
			(setq eo (vlax-ename->vla-object e))
			(setq co (vlax-ename->vla-object c))
			(setq p1 (vlax-curve-getStartPoint eo))
			(setq p2 (vlax-curve-getEndPoint eo))
			(setq l
				(entmakex
					(list
						(cons 0 "LINE")
						(cons 100 "ACDbEntity")
						(cons 100 "ACDbLine")
						(cons 10 (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5)))
						(cons 11 (polar (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5))(+ (angle p1 p2) (* 0.5 PI)) 1))
					)
				)
			)
			(setq lo (vlax-ename->vla-object l))
			(setq p3 (getintersections lo co ))
			(entdel l)
			(setvar 'cmdecho 0)
			(command "_.line" "_none" p1 "_none" p3 "")
			(command "_.line" "_none" p2 "_none" p3 "")
			(setvar 'cmdecho 1)
			(vla-endundomark adoc)
		)
	)
	(princ)
)

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 14

john.uhden
Mentor
Mentor

Alrighty then,

This simple one lets you draw the triangle at any angle...

(defun c:isosceles ( / p1 p2 p3 ang ht)
  (and
    (setq p1 (getpoint "\n1st end of base line: "))
    (setq p2 (getpoint p1 "\n2nd end of base line: "))
    (setq ht (getdist "\nHeight of triangle: "))
    (setq ang (angle p1 p2))
    (setq p3 (polar p1 ang (* 0.5 (distance p1 p2))))
    (setq p3 (polar p3 (+ ang (/ pi 2)) ht))
    (vl-cmdf "_.pline" "_non" p1 "_non" p2 "_non" p3 "_C")
  )
  (princ)
)

 

John F. Uhden

Message 10 of 14

-didier-
Advisor
Advisor
Accepted solution

Bonjour @carlos_m_gil_p 

 

I propose this lsp with which you only have to write the two lines, (base first, objective second)

I am at your disposal to improve it if necessary (color, layer...)

 

;|
demande sur le forum anglais de carlos.gil.p du 07 octobre 2021
tracé triangle isocèle depuis ligne de base et ligne objectif
les deux lignes sont à sélectionner à l'écran
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/create-isosceles-triangle/m-p/10673622#M421555
|;
(defun c:TRIS2L (/ int l1 l2 p1 p2 p3 p4 pmil proj int)
  (setq oldosmode (getvar "osmode"))
  (setq l1 (car (entsel "\nBase Line\n")))
  (setq l2 (car (entsel "\nLine Object\n")))
  (if
    (and (= "LINE" (cdr (assoc 0 (entget l1))))
           (= "LINE" (cdr (assoc 0 (entget l1))))
           )
    (progn
      (setq p1 (cdr (assoc 10 (entget l1)))
            p2 (cdr (assoc 11 (entget l1)))
            p3 (cdr (assoc 10 (entget l2)))
            p4 (cdr (assoc 11 (entget l2)))
            pmil (mapcar '(lambda (a b ) (/ (+ a b) 2.0)) p1 p2)
            proj (polar pmil (- (angle p1 p2) (/ pi 2.0)) 1)
            int (inters pmil proj p3 p4 nil)
            )
      (entmake (cons '(0 . "LINE") (mapcar 'cons '(10 11) (list p1 int))))
      (entmake (cons '(0 . "LINE") (mapcar 'cons '(10 11) (list p2 int))))
      )
    (progn
      (alert "incorrect selection of entities")
      (setvar "osmode" oldosmode)
      )
    )
)
(prompt "Command Name : TRIS2L TRiangle ISosceles 2 Lines")
(princ)

      

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 11 of 14

hak_vz
Advisor
Advisor

@john.uhden  What is with your Expert elite signature. It shows message "Image doesn't exist or no longer available "

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 12 of 14

-didier-
Advisor
Advisor

Bonjour @hak_vz 

 

I sympathize with John because putting elite signatures is not very simple!

 

Amicalemeny

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 13 of 14

carlos_m_gil_p
Advocate
Advocate

Hello boys how are you.
All the options work very well.
 In this case I don't know the height, but it may work for another time.
Thank you very much to all.
Thank you for helping me and teaching me every new day more.
Greetings.


AutoCAD 2026.1.1
Visual Studio Code 1.105.1
AutoCAD AutoLISP Extension 1.6.3
Windows 10 - 22H2 (64 bits)

0 Likes
Message 14 of 14

john.uhden
Mentor
Mentor
Thanks, @hak_vz. I'm glad you mentioned it.
Back when, @Jeff_M (Jeff Mishler) gave me his avatar to use. So I just
pasted it and changed the name. But not too long ago, the image
(referenced from on-line somewhere) disappeared. And I don't know how to
get one back or use another.

John F. Uhden

0 Likes