Author Topic: Draw a 3 pt rectangle  (Read 7570 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Draw a 3 pt rectangle
« on: September 21, 2005, 05:42:29 PM »
Hey Paul,
If you are looking for a new 3 point rectangle routine you may
want to try this one. 8-)

Code: [Select]
;;  CAB  09/21/2005
;;  3 point rectangle for drawing rotated rectangles
;;  note that the 2nd point is for angle only an need not be the
;;  the actual corner
(defun c:rec3pt (/ p1 p2 p3 p4 pp ang useros)
  (if
    (and (setq p1 (getpoint "\nPick corner."))
         (setq p2 (getpoint p1 "\n* Pick adjacent corner."))
         (setq p3 (getpoint p2 "\n** Pick next adjacent corner."))
    )
     (progn
       (setq useros (getvar "osmode"))
       (setvar "osmode" 0)
       ;; angle  perpendicular to line
       (setq ang (+ (angle p1 p2) (/ pi 2.0))
             pp  (polar p3 ang 100)
             p2  (inters p1 p2 p3 pp nil)
             p4  (polar p1 (angle p2 p3) (distance p2 p3))
       )
       (command "._pline" p1 p2 p3 p4 "c")
       (setvar "osmode" useros)
     )
  )
  (princ)
)
(prompt "\nThree point Rectangle Loaded, Enter rec3pt yo run.")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Amsterdammed

  • Guest
Re: Draw a 3 pt rectangle
« Reply #1 on: September 22, 2005, 07:39:27 AM »
Cab
I admire your work but i think this will be an improvement

Code: [Select]
(defun c:rec3pt (/ p1 p2 p3 p4 pp ang useros)
(setq usersa (getvar "Snapang"))
  (if
    (and (setq p1 (getpoint "\nPick corner."))
         (setq p2 (getpoint p1 "\n* Pick adjacent corner."))
         (setvar "snapang" (angle p1 p2))
         (setvar "orthomode"1)
         (setq p3 (getpoint p2 "\n** Pick next adjacent corner."))
    )
     (progn
       (setq useros (getvar "osmode"))
       (setvar "osmode" 0)
       ;; angle  perpendicular to line
       (setq ang (+ (angle p1 p2) (/ pi 2.0))
             pp  (polar p3 ang 100)
             p2  (inters p1 p2 p3 pp nil)
             p4  (polar p1 (angle p2 p3) (distance p2 p3))
       )
       (command "._pline" p1 p2 p3 p4 "c")
       (setvar "osmode" useros)
         (setvar "Snapang" usersa))
     )
  )
  (princ)
)
(prompt "\nThree point Rectangle Loaded, Enter rec3pt yo run.")
(princ)



Bernd

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Draw a 3 pt rectangle
« Reply #2 on: September 22, 2005, 08:18:05 AM »
Bernd,
Good idea.
My intent was to allow the user freedom of not accurately picking the second
point. Just to establish the angle.
I think your example would be more like most would use the routine.
And improvement is in the eye of the beholder. :-)

Thanks
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Amsterdammed

  • Guest
Re: Draw a 3 pt rectangle
« Reply #3 on: September 22, 2005, 09:03:15 AM »
Cab,
I'm glad you liked the Idea.

Bernd

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Draw a 3 pt rectangle
« Reply #4 on: September 23, 2005, 04:17:40 PM »
Nice work CAB..

but there is mine..

Code: [Select]
;| 3 points rectangle ;;
AndreaLISP  2005/09/23 |;

(defun c:3prec (/ p1 p2 p3 p4)
 
;;get the default value
(setq osmode (getvar "OSMODE"))
(setq orthomode (getvar "ORTHOMODE"))
(setq snapang (getvar "SNAPANG"))

(setq p1 (getpoint "\nFirst corner."))
(setq p2 (getpoint p1 "\nSecond corner."))
(vl-cmdf "_.snapang" (/ (* (angle p1 p2) 180) pi))
(setvar "ORTHOMODE" 1)
(setq p3 (getpoint p2 "\nThird corner."))
(setq p4 (polar p1 (angle p2 p3) (distance p2 p3))) 
(command "_.pline" p4 p1 p2 p3 "_C")
(resetvar_rec3pt)(princ) 
);;defun

;;; RESET VARIABLES
(defun resetvar_rec3pt ()
(setvar "osmode" osmode)
(setvar "snapang" snapang)
(setvar "orthomode" orthomode)
)

(princ "\n\n Type \"r3pt\" to start.")
« Last Edit: September 24, 2005, 10:29:37 PM by Andrea »
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Draw a 3 pt rectangle
« Reply #5 on: September 23, 2005, 05:17:38 PM »
It's a mark of our uniqueness I s'pose .. I have these prompts.

Command: rotRec

Select First Corner :
Select Rotation Angle :
Select Adjacent Corner :
Select Next Corner :


Andrea, you may want to check your variable names. Yours will spit the dummy I think.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Draw a 3 pt rectangle
« Reply #6 on: September 23, 2005, 05:59:17 PM »
Here is a sweet routine....think it was Smadsen that created it....


Code: [Select]
;; Main command (rename to whatever)
(defun C:ROTREC () (rectang))

;; Command driven pline creator
(defun drawRect (p1 p2 a dist)
  (setq p3 (polar p2 (+ a (/ pi 2.0)) dist)
p4 (polar p1 (+ a (/ pi 2.0)) dist)
  )
  (command "_PLINE" p1 p2 p3 p4 "Close")
)

;; Ghost graphic creator
(defun draw (p1 p2 p3 a / p4 p5 pd)
  (redraw)
  (setq pd (* (distance p1 p3) (sin (- (angle p1 p3) a))))
  (grvecs (list 7
p1
p2 ; base leg
7
p1
(setq p4 (polar p1 (+ a (/ pi 2.0)) pd)) ; "bottom" leg
7
p2
(setq p5 (polar p2 (+ a (/ pi 2.0)) pd)) ; "top" leg
7
p4
p5 ; opposite leg
  )
  )
)

;; Prompt output (all this only to allow for backspace)
(defun goPrinc (prmpt str / llen lstr)
  (princ "\r")
  (setq lstr (substr str 1 (strlen str)))
  (setq llen (1+ (strlen lstr)))
  (repeat llen (princ "\010"))
  (repeat llen (princ " "))
  (repeat llen (princ "\010"))
  (princ (strcat prmpt str))
)

;; Main sub with GRREAD
(defun rectang
       (/ ang char code data final flag p prmpt pt1 pt2 rstr str)
  (cond
    ((and (setq pt1 (getpoint "\nStart point: "))
  (setq pt2 (getpoint pt1 "\nEnd point for base leg: "))
     )
     (setq ang (angle pt1 pt2)
   prmpt "Opposite leg or length: "
   str ""
   flag T

     )
     (terpri)
     (princ prmpt)
     (while flag
       (setq p   (grread T 11)
     code (car p)
     data (cadr p)
       )
       (cond
((= code 5)
  (draw pt1 pt2 data ang)
)
((= code 3)
  ;; clicked point .. accept it and get on with it
  (setq final data
flag  nil
  )
)
((= code 2)
  (setq char data)
  (cond
    ((= 46 char)
     ;; a period was entered
     ;; check to see if a period already exists
     (if (not (vl-string-search "." str))
       (setq str (strcat str (chr char)))
     )
     (goPrinc prmpt str)
    )
    ((<= 48 char 57)
     ;; if input is a number then append it
     (princ (chr char))
     (setq str (strcat str (chr char)))
     (goPrinc prmpt str)
    )
    ((= char 8)
     ;; backspace was hit .. go chop off a character
     (setq str (substr str 1 (max 0 (1- (strlen str)))))
     (goPrinc prmpt str)
    )
    ((member char '(13 32))
     ;; If enter or space then see if str
     ;;  holds a number
     ;; This *should* check str for all allowed syntaxes!
     (cond
       ((and (/= str "")
     (numberp
       (setq rstr (vl-catch-all-apply 'read (list str)))
     )
)
(setq final (float rstr)
      flag  nil
)
       )
       ((= str "") (setq flag nil))
       ((princ "\nRequires numeric distance or a point")
(setq str "")
(goPrinc prmpt str)
       )
     )
    )
  )
)
       )
     ) ;_ while
     (redraw)
     (cond ((vl-consp final)
    (drawRect
      pt1
      pt2
      ang
      (* (distance pt1 final) (sin (- (angle pt1 final) ang)))
    )
   )
   ((numberp final)
    (drawRect pt1 pt2 ang final)
   )
     )
    ) ;_ cond pt1 and pt2
  )
  (princ)
)

(setfunhelp "c:rotrec" "acadtools.chm" "rotrec")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Draw a 3 pt rectangle
« Reply #7 on: September 23, 2005, 06:09:55 PM »
ron,
that's a cool one.
Did you try this one yet? It uses the diaganal points.
http://www.theswamp.org/forum/index.php?topic=6958.msg85460#msg85460
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Draw a 3 pt rectangle
« Reply #8 on: September 23, 2005, 06:15:26 PM »
oh, yeah, I almost forgot. If you're using AC2006 the original RECTANGLE command may be worth a revisit.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Draw a 3 pt rectangle
« Reply #9 on: September 23, 2005, 06:44:42 PM »
ron
That was so cool I revised may rectangle angle routine to pick the
same way that one does.

Code: [Select]
;;;=======================[ Rec3pts.lsp ]=======================
;;; Author:  Charles Alan Butler
;;; Version:  1.0   Sept. 21, 2005
;;; Purpose: To allow user to draw a rectangle by picking 3
;;;   points, the 3rd point allows for streatching the rectangle
;;; Sub_Routines: -GetRectDiag
;;; Requirements: -None
;;; Returns: -Nothing
;;;==============================================================
;;;  Pick 2 points to define one side of the rectangle, the using
;;;  grread change the height to redraw the rectangle
(defun c:rec3pts (/ p1 p2 lst useros)
  (if
    (and (setq p1 (getpoint "\nPick corner."))
         (setq p2 (getpoint p1 "\n* Pick adjacent corner."))

    )
     (progn
       (setq lst (getrectdiag p1 p2))

       (setq useros (getvar "osmode"))
       (setvar "osmode" 0)

       (command "._pline")
       (apply 'command lst)
       (command "c")
       (setvar "osmode" useros)
     )
  )
  (princ)
)
(prompt "\n3 point Rectangle Loaded, Enter Rec3pts to run.")
(princ)

;;;=======================[ GetRectDiag.lsp ]=======================
;;; Author:  Charles Alan Butler
;;; Version:  1.0   Sept. 23, 2005
;;; Purpose: To allow user to size a rectangle by picking a 3rd point
;;; Sub_Routines: -None
;;; Requirements: -Two adjacent corner points
;;; Returns: -List of corner points
;;;==============================================================
;;;  change the height to redraw the rectangle using grread
;;;  show new rectangle based on two fixed points ,
;;;  user picks the height
(defun getrectdiag (ll lr / track upt ur ul pp ang pang)

  (setq pang (+ (angle ll lr) (/ pi 2.0)); angle perpendicular to line
        ang (angle ll lr)
        pp  (polar lr pang 100) ; perpendicular point
        )
  (while (= 5 (car (setq track (grread t 5 1))))
    (redraw)
    (setq upt (cadr track)) ; user point

    ;;  calc the new rectangle
    (setq ur  (inters lr pp upt (polar upt ang 100) nil)
          ul  (polar ll (angle lr ur) (distance lr ur))
    )

    ;; draw the rectangle
    (grvecs (list -256 ll lr -256 lr ur -256 ur ul -256 ul ll))
  ) ; while
  (redraw)
  (list ll lr ur ul) ; return list of points 
)
« Last Edit: September 24, 2005, 08:38:27 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Draw a 3 pt rectangle
« Reply #10 on: September 24, 2005, 12:03:21 AM »
It's a mark of our uniqueness I s'pose .. I have these prompts.

Command: rotRec

Select First Corner :
Select Rotation Angle :
Select Adjacent Corner :
Select Next Corner :


Andrea, you may want to check your variable names. Yours will spit the dummy I think.

hug !?? :|
Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Draw a 3 pt rectangle
« Reply #11 on: September 24, 2005, 12:43:48 AM »
hug !?? :|
Have you run that routine ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Draw a 3 pt rectangle
« Reply #12 on: September 24, 2005, 02:40:15 AM »
I mean this :


;;get the default value
(setq osmode (getvar "OSMODE"))
.......

;;; RESET VARIABLES
.......
(setvar "osmode" useros )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Draw a 3 pt rectangle
« Reply #13 on: September 24, 2005, 10:30:35 PM »
thanks...I have corrected...
wrong cut&paste. :lmao:
Keep smile...

t-bear

  • Guest
Re: Draw a 3 pt rectangle
« Reply #14 on: September 28, 2005, 02:17:44 PM »
Charles,
The routine has a glitch (or it might well be me....).  I can use coordinate entry for the first two points but not the third.  I can stretch the rect, but can't enter a distance.  For it to be useful, I'd need that ability.  Am I missing something here?