Jump to content

Need Rectangle Lisp !!!!


Guest

Recommended Posts

1) Rectangle with sides and direction

Have two points (or one and the second distance) to one side of the rectangle.

Once defined the first side designed temporary line of infinite length in the vertical direction and distance that the first length provided.

You can select the second point of the rectangle for this temporary line or give the length and will be designed automatically.

(look photo 1)

 

2) Rectangle with 4 points (one for each side)

Give one point for each side of the rectangle drawn Rectangle that includes these points.

 

(look photo 2)

1.jpg

2.png

Link to comment
Share on other sites

  • Replies 36
  • Created
  • Last Reply

Top Posters In This Topic

  • Tyke

    10

  • Lee Mac

    4

  • Tharwat

    4

  • hmsilva

    4

Top Posters In This Topic

Posted Images

The answer to the second question is that you cannot do it. With four points as shown, you could rotate the rectangle and still get it to pass through the four points, albeit the rectangle would be a different size.

 

Not quite sure that I understand your first question, but it would appear from you last post you have that solved.

Link to comment
Share on other sites

any help please i need this lisp ..............

 

Alan's LISP:

 

(defun c:BX (/ foo _dist p1 p2 p3 ang)
 ;; Draw rectangle based on 2 or 3 picked points
 ;; Alan J. Thompson, 07.26.10

 (defun foo (l)
   (entmake
     (append '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (90 . 4) (70 . 129))
             (mapcar (function (lambda (p) (cons 10 (reverse (cdr (reverse (trans p 1 0))))))) l)
     )
   )
 )

 (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))

 (if (and (setq p1 (getpoint "\nSpecify first point: "))
          (setq p2 (getpoint p1 "\nSpecify second point: "))
          (not (grdraw p1 p2 3 1))
     )
   (if (setq p3 (initget 0 "Left Right")
             p3 (getpoint p2 "\nSpecify third point or Square box or [Left/Right]: ")
       )
     (cond ((vl-consp p3) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2)))))
           ((eq (type p3) 'STR)
            (cond
              ((eq p3 "Left") (setq ang (+ (/ pi 2.) (angle p1 p2))))
              ((eq p3 "Right") (setq ang (+ (* pi 1.5) (angle p1 p2))))
            )
            (foo (list p1 p2 (polar p2 ang (_dist p1 p2)) (polar p1 ang (_dist p1 p2))))
           )
     )
   )
 )
 (redraw)
 (princ)
)

Link to comment
Share on other sites

What about 2) Rectangle with 4 points (one for each side)

Give one point for each side of the rectangle drawn Rectangle that includes these points.

Link to comment
Share on other sites

As I said in post #5 you cannot do a rectangle with one point for each side. It is possible to draw lots of rectangles through the points. Check out this image.

rectangle.jpg

Link to comment
Share on other sites

Try this and let me know ..

 

(defun c:Test (/ p1 p2 p3 p4 l1 x1 x2 l2 y1 y2)
 (and (setq p1 (getpoint "\n First point :"))
      (setq p2 (getpoint "\n Second Point :"))
      (setq p3 (getpoint "\n Third Point :"))
      (setq p4 (getpoint "\n Forth Point :"))
 )
 (progn
   (setq l1 (mapcar 'car (list p1 p2 p3 p4)))
   (setq x1 (apply 'max l1))
   (setq x2 (apply 'min l1))
   (setq l2 (mapcar 'cadr (list p1 p2 p3 p4)))
   (setq y1 (apply 'max l2))
   (setq y2 (apply 'min l2))
   (command "_.rectang"
            "_non"
            (list x1 y2)
            "_non"
            (list x2 y1)
   )
 )
 (princ)
)

Link to comment
Share on other sites

The LISP draws a rectangle through the four points, but the sides of the rectangle are vertical and horizontal. For this situation you have multiple solutions when the rectangle's sides are not horizontal and vertical, see my post #11 with example image.

 

The OP then asked if with one corner point and three points on the sides if it would be possible and it is. I would have thought of picking the corner point first and then the other points, then constructing the figure as the rectangle command will only work for horizontal and vertical sides.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...