### Author Topic: Square - Rectangle lisp  (Read 1099 times)

0 Members and 1 Guest are viewing this topic.

#### pedroantonio

• Guest
##### Square - Rectangle lisp
« 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

#### ronjonp

• Needs a day job
• Posts: 7071
##### Re: Square - Rectangle lisp
« Reply #1 on: May 22, 2019, 01:02:06 PM »
How would you solve this without more input

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

#### CAB

• Global Moderator
• Seagull
• Posts: 10376
##### Re: Square - Rectangle lisp
« Reply #2 on: May 22, 2019, 01:07:32 PM »
Some code help to get you started.
https://www.theswamp.org/index.php?topic=54892.0

And more ideas from Lee Mac:
http://www.lee-mac.com/3pointrectangle.html
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970

#### pedroantonio

• Guest
##### Re: Square - Rectangle lisp
« Reply #3 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

#### PKENEWELL

• Bull Frog
• Posts: 229
##### Re: Square - Rectangle lisp
« Reply #4 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.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

#### pedroantonio

• Guest
##### Re: Square - Rectangle lisp
« Reply #5 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

#### kdub

• Mesozoic relic
• SuperMod
• Swamp Rat
• Posts: 1366
• class keyThumper<T>:ILazy<T>
##### Re: Square - Rectangle lisp
« Reply #6 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.
« Last Edit: May 22, 2019, 07:25:32 PM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

#### pedroantonio

• Guest
##### Re: Square - Rectangle lisp
« Reply #7 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

#### kdub

• Mesozoic relic
• SuperMod
• Swamp Rat
• Posts: 1366
• class keyThumper<T>:ILazy<T>
##### Re: Square - Rectangle lisp
« Reply #8 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.

called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

#### pedroantonio

• Guest
##### Re: Square - Rectangle lisp
« Reply #9 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

#### kdub

• Mesozoic relic
• SuperMod
• Swamp Rat
• Posts: 1366
• class keyThumper<T>:ILazy<T>
##### Re: Square - Rectangle lisp
« Reply #10 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.

« Last Edit: May 23, 2019, 02:04:23 AM by kdub »
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

#### ronjonp

• Needs a day job
• Posts: 7071
##### Re: Square - Rectangle lisp
« Reply #11 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.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

#### domenicomaria

• Mosquito
• Posts: 16
##### Re: Square - Rectangle lisp
« Reply #12 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 "")
)

« Last Edit: May 23, 2019, 05:12:13 PM by domenicomaria »

#### domenicomaria

• Mosquito
• Posts: 16
##### Re: Square - Rectangle lisp
« Reply #13 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 "")
)

#### domenicomaria

• Mosquito
• Posts: 16
##### Re: Square - Rectangle lisp
« Reply #14 on: May 24, 2019, 04:51:03 AM »
ANGDIR is ANTI-CLOCKWISE
and
2PI=360°

. . .
however
for the RECTANGLE
there are 2 SOLUTIONS . . .