# TheSwamp

## Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pedroantonio on May 22, 2019, 12:01:12 PM

Title: Square - Rectangle lisp
Post by: pedroantonio on May 22, 2019, 12:01:12 PM
Hi. i am searching for a lisp to draw a rectangle or square (have two options)  from two points. I know the rectangle command but is not what i am searching because the rectangle command can not understand the orientation. I am using grads for the angle but i think if we know the diagonal  of the rectangle or the square we can draw a perfect rectangle or square
Title: Re: Square - Rectangle lisp
Post by: ronjonp on May 22, 2019, 01:02:06 PM
How would you solve this without more input  :wink:
Title: Re: Square - Rectangle lisp
Post by: CAB on May 22, 2019, 01:07:32 PM
Some code help to get you started.
https://www.theswamp.org/index.php?topic=54892.0 (https://www.theswamp.org/index.php?topic=54892.0)

And more ideas from Lee Mac:
http://www.lee-mac.com/3pointrectangle.html (http://www.lee-mac.com/3pointrectangle.html)
Title: Re: Square - Rectangle lisp
Post by: pedroantonio on May 22, 2019, 05:12:49 PM
Hi ronjonp. You can pick an extra point to select the side for the red or yellow rectangle
Title: Re: Square - Rectangle lisp
Post by: PKENEWELL on May 22, 2019, 05:39:57 PM
@ Topographer,

If you are talking about the compliment angle (90 - the angle of the 2 points), then you don't need a LISP to do this. Just rotate your UCS around the Z-axis to the angle desired and used the RECTANG command. Otherwise - you need to describe what you your relational angle is to the 2 points.
Title: Re: Square - Rectangle lisp
Post by: pedroantonio on May 22, 2019, 05:49:14 PM
hi PKENEWELL. I use this unit settings. I didn't understand exactly your question . When i pick 2 points  i can calculate the angle
Title: Re: Square - Rectangle lisp
Post by: kdub on May 22, 2019, 07:18:59 PM
Topographer,

What do you expect the UCS to be when you draw the rectangle?

What do you expect the SnapAngle to be when you draw the rectangle ?

What information do you expect to provide to draw the rectangle ?

Without these answers explicitly you are wasting our time.

hi PKENEWELL. I use this unit settings. I didn't understand exactly your question . When i pick 2 points  i can calculate the angle

Calculate the angle relative to what ?

The SQUARE is easy .. The sides length and orientation are related to the diagonal line because of the diagonal bisects the 90 deg corner.

Have a think about the information you need to provide for the rectangle.
Title: Re: Square - Rectangle lisp
Post by: pedroantonio on May 23, 2019, 01:26:55 AM
Hi kdub. I dont ave the answer for all this questions. The only things i know is in my first post, like the 2 photos. pick two points in any direction and create rectangle or square. I want the diagonal of this object to fit between two points. Then if is necessary i will rotate iit or move it.

Thanks
Title: Re: Square - Rectangle lisp
Post by: kdub on May 23, 2019, 01:32:39 AM
As I said ;
The square can be done.
The rectangle requres more input from you regarding design.
The least you can do is decide how you want the rectangle oriented and sized ... I assume it is a design requirement  ... or else a whim.

Title: Re: Square - Rectangle lisp
Post by: pedroantonio on May 23, 2019, 01:42:03 AM
Hi  kdub. The rectangle is two triangles with angles in degrees (90,60,30) .You know the length  between pt1 and pt2 ,and you have the orientation from points pt1 and pt2. Then you have to create two triangles . I think that you don't need anything else
Title: Re: Square - Rectangle lisp
Post by: kdub on May 23, 2019, 02:01:11 AM
Good, that info will do. You can mirror/rotate the rectangle if needed.

How about you start programming and let us know when you hit a wall.

Title: Re: Square - Rectangle lisp
Post by: ronjonp on May 23, 2019, 10:06:40 AM
Hi  kdub. The rectangle is two triangles with angles in degrees (90,60,30) .You know the length  between pt1 and pt2 ,and you have the orientation from points pt1 and pt2. Then you have to create two triangles . I think that you don't need anything else
You're half way there! Let's see some code and maybe we can help out.  :-)
Title: Re: Square - Rectangle lisp
Post by: domenicomaria on May 23, 2019, 05:03:44 PM
Do you want mean this ?

(defun :GR (a) (* pi (/ a 180.0)))

(defun C:RCT ( / ANG12 ANG1X ANG2X P1 P2 PXL PXR)
(setq p1 (getpoint "\nfirst point :"))
(setq p2 (getpoint p1 "\nsecond point :"))
(setq   ang12   (angle p1 p2)
ang2x   (+ ang12 (:GR 120.0))
ang1x   (+ ang12 (:GR 30.0))
)
(setq pxl (inters p2 (polar p2 ang2x 1.0) p1 (polar p1 ang1x 1.0) nil))

(setq pxr (inters p1 (polar p1 (+ ang2x pi) 1.0) p2 (polar p2 (+ ang1x pi) 1.0) nil))

(vl-cmdf "line" p1 p2 "")
(vl-cmdf "pline" p1 pxr p2 pxl p1 "")
)

Title: Re: Square - Rectangle lisp
Post by: domenicomaria on May 23, 2019, 05:14:16 PM

while this is for the SQUARE . . .

(defun C:SQR ( / ANG12 ANG1X ANG2X P1 P2 PXL PXR)
(setq p1 (getpoint "\nfirst point :"))
(setq p2 (getpoint p1 "\nsecond point :"))
(setq   ang12   (angle p1 p2)
ang2x   (+ ang12 (:GR 135.0))
ang1x   (+ ang12 (:GR 45.0))
)
(setq pxl (inters p2 (polar p2 ang2x 1.0) p1 (polar p1 ang1x 1.0) nil))

(setq pxr (inters p1 (polar p1 (+ ang2x pi) 1.0) p2 (polar p2 (+ ang1x pi) 1.0) nil))

(vl-cmdf "line" p1 p2 "")
(vl-cmdf "pline" p1 pxr p2 pxl p1 "")
)
Title: Re: Square - Rectangle lisp
Post by: domenicomaria on May 24, 2019, 04:51:03 AM
ANGDIR is ANTI-CLOCKWISE
and
2PI=360°

. . .
however
for the RECTANGLE
there are 2 SOLUTIONS . . .
Title: Re: Square - Rectangle lisp
Post by: BIGAL on May 24, 2019, 08:34:38 PM
Like you ronjonp 3 answers actually 4 say left right ortho and square. for 1st 3 enter length of other side, need 2 knowns.
Title: Re: Square - Rectangle lisp
Post by: domenicomaria on May 25, 2019, 04:02:39 AM
Topographer
you say :
"The rectangle is two triangles with angles in degrees (90,60,30)"

But this is NOT TRUE.
It could be so, but it is not the rule.

If you want that
"the rectangle is two triangles with angles in degrees (90,60,30)"
the code that i wrote
is the almost the solution
(because there is also the mirrored solution)