TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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

How would you solve this without more input :wink:

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.leemac.com/3pointrectangle.html (http://www.leemac.com/3pointrectangle.html)

Hi ronjonp. You can pick an extra point to select the side for the red or yellow rectangle

@ 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 Zaxis to the angle desired and used the RECTANG command. Otherwise  you need to describe what you your relational angle is to the 2 points.

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

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 ?
added:
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.

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

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.

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

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.

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. :)

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))
(vlcmdf "line" p1 p2 "")
(vlcmdf "pline" p1 pxr p2 pxl p1 "")
)

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))
(vlcmdf "line" p1 p2 "")
(vlcmdf "pline" p1 pxr p2 pxl p1 "")
)

ANGDIR is ANTICLOCKWISE
and
2PI=360°
. . .
however
for the RECTANGLE
there are 2 SOLUTIONS . . .

Like you ronjonp 3 answers actually 4 say left right ortho and square. for 1st 3 enter length of other side, need 2 knowns.

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)