Function to create Trapezoid with indent

Function to create Trapezoid with indent

rpajounia
Advocate Advocate
377 Views
6 Replies
Message 1 of 7

Function to create Trapezoid with indent

rpajounia
Advocate
Advocate

so im currently using the function below to create a trapezoid

 

(defun _trap (p1 p2 p3 p4 / lt point2d x1 y1 x2 y2 pts q)
      (defun lt (pt) (trans pt 1 0))
      (defun point2d (pt) (list (car pt) (cadr pt)))
        ;(command "_.ucs" "w")
      (princ "doing setq")
      (setq
            x1 (apply 'min (mapcar 'car (list p1 p2)))
            y1 (apply 'min (mapcar 'cadr (list p1 p2)))
            x2 (apply 'max (mapcar 'car (list p1 p2)))
            y2 (apply 'max (mapcar 'cadr (list p1 p2)))
          pts (mapcar 'point2d(mapcar 'lt (list (list x1 y1) (list x2 y1) (list x2 (+ y1 p4) ) (list (- x2 p3) y2) (list (+ x1 p3) y2) (list x1 (+ y1 p4) ) )))
      )
 
      (cond
            ((and pts)
                  (setq q (entmakex
                        (apply 'append
                              (cons
                                (list
                                    '(0 . "LWPOLYLINE")
                                    '(100 . "AcDbEntity")
                                    '(100 . "AcDbPolyline")
                                    '(410 . "Model")
                                    '(8 . "0")
                                    '(38 . 0)
                                    '(62 . 256)
                                    '(67 . 0)
                                    (cons 90 (length pts))
                                    '(70 . 1)
                                )
                                (mapcar 'list (mapcar '(lambda (a) (cons 10 a)) pts))
                              )
                        )
                  ))
            )
      )
      q
)

, but what i need now is a function that will make a trapezoid with indents im just not sure how to do the math on it, can any1 help? i have a picture as an attachment where i will give 7 points to make it happen instead of 4 

0 Likes
378 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

Your diagram is inaccurate.  Given the orthogonal perimeter lengths, the total along the diagonals would not be the sum of the diagonal lengths shown (18) but a little over 18.2.  What is the intent?  Are those diagonals supposed to be at 45° angles [which they can't be with the orthogonal lengths shown]?

 

Can you re-post the image showing us where the four points [arguments to the function] are in relation to the drawn Polyline? [EDIT:  Looking more closely, it appears p3 and p4 are not points, but numbers apparently for lengths.  Include an indication of where those lengths are.]

 

Would the length and depth of the indent and the distance of one end of it from some corner [which one?] be constant, or fed in as arguments like the four points/lengths, or would it need to ask the User for those?

 

[Further EDIT:  And Trapezoid is not the right word.  Maybe Truncated Rectangle?  But maybe not, if that implies truncating all corners of the original....]

Kent Cooper, AIA
0 Likes
Message 3 of 7

hak_vz
Advisor
Advisor

@Kent1Cooper  As you can see in the code provided by @rpajounia  the "signature" (and ) usage. This is the code I created for him I don't remember when.  You are correct: P1 P2 are points of rectangle, and p3 p4 are truncation lengths

 

TRAPEZOID.png

 

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 4 of 7

CodeDing
Advisor
Advisor

@rpajounia ,

 

I would recommend Dynamic BLocks for things like this (you can code their inputs if you want still)

 

See attached

 

image.png

 

Best,

0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....

Would the length and depth of the indent and the distance of one end of it from some corner [which one?] be constant, or fed in as arguments like the four points/lengths, or would it need to ask the User for those?

....


Or another possibility:  would they be calculated as something like proportions of the overall diagonal length?

Kent Cooper, AIA
0 Likes
Message 6 of 7

hak_vz
Advisor
Advisor

@rpajounia Try this

 

(defun c:trap2 (/ *error* lt p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 w h a b c d e pts m s  ang1 ang2 ang3 ang4)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(princ)
	)
	(defun lt (pt) (trans pt 1 0))
	  (setq p1 (getpoint "\nPick start point > "))
	  (setq w (getreal "\nTotal width  (w)> "))
	  (setq h (getreal "\nTotal height (h)> "))
	  (setq a (getreal "\nWidth at top (a)> "))
	  (setq b (getreal "\nSide height (b)> "))
	  (cond
		((and p1 w h a b)
			(setq 
				x1 (car p1) y1 (cadr p1)
				x2 (+ x1 w) y2 y1
				x3 x2 y3 (+ y2 b)
				x14 x1 y14 y3
				s (* 0.5 (- w a))
				x8 (- x2 s) y8 (+ y1 h)
				x9 (+ x1 s) y9 y8
				p1 (list x1 y1)
				p2 (list x2 y2)
				p3 (list x3 y3)
				p8 (list x8 y8)
				p9 (list x9 y9)
				p14 (list x14 y14)
			)
			(princ (strcat "\Available total lenght along slope is " (rtos (distance p3 p8) 2 4)))
			(setq
				c (getreal "\n C > ")
				d (getreal "\n D > ")
				e (getreal "\n E > ")
				ang1 (angle p8 p3)
				ang2 (angle p9 p14)
				m (* 0.5 pi)
				ang3 (- ang1 m)
				ang4 (+	ang2 m)
				p7 (polar p8 ang1 c)
				p6 (polar p7 ang3 e)
				p5 (polar p6 ang1 d)
				p4 (polar p7 ang1 d)
				
				p10(polar p9 ang2 c)
				p11(polar p10 ang4 e)
				p12(polar p11 ang2 d)
				p13(polar p10 ang2 d)
				pts (mapcar 'lt (list p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14))
			)
		(setq q 
		  (entmakex
				(apply 'append
					  (cons
						(list
							'(0 . "LWPOLYLINE")
							'(100 . "AcDbEntity")
							'(100 . "AcDbPolyline")
							'(410 . "Model")
							'(8 . "0")
							'(38 . 0)
							'(62 . 256)
							'(67 . 0)
							(cons 90 (length pts))
							'(70 . 1)
						)
						(mapcar 'list (mapcar '(lambda (a) (cons 10 a)) pts))
					  )
				)
			)
		)
		)
	)
	(princ)
)

 

TRAPEZOID 2.png

 

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 7

Sea-Haven
Mentor
Mentor

Very nice diagram of the shape, I keep saying to people get a pen and paper, write down the point numbers then you know where your at working out the next point.

 

Your welcome to use something like this. Can supply code etc. Needs a few more values.

SeaHaven_0-1707192852345.png

 

 

 

0 Likes