What is the most efficient way that I could do this lisp?

What is the most efficient way that I could do this lisp?

Anonymous
Not applicable
3,726 Views
32 Replies
Message 1 of 33

What is the most efficient way that I could do this lisp?

Anonymous
Not applicable

'm starting in the Lisp routines, and wanted to know how efficiently I could do it, the intention is to make Lisp draw several rectangles (polylines) based on the three points, p1, p2 p3.

 

(defun c:CTeste001 (/ p1 p2 p3 p4)
(setq p1 (getpoint "\nPOINT <P1>")
p2 (getpoint "\nPOINT <P2>")
p3 (getpoint "\nPOINT <P3>")
p4 (getreal "\nQuantities? <Quant>"))
)

 

im01.pngi02.png

0 Likes
Accepted solutions (2)
3,727 Views
32 Replies
Replies (32)
Message 2 of 33

john.uhden
Mentor
Mentor

A few questions...

 

1.  Are p1, p2, p3 always supposed to form a right triangle?

2.  If yes, do you want to check for right angularity and inform the user if not, and stop?

3.  If not, then are the resulting figures supposed to be trapezoids?

4.  Is the quantity always measured along the longer leg?

5.  Will the elevation of all three points always be the same (as each other)?

6.  Are the resulting boxes supposed to be closed polylines, or just lines?

 

As to #1 and #2, it would be possible to try to force a right angle after the first two picks by setting a perpendicular snapang and turning on orthomode.  Of course the order of the picks makes a huge difference.  We have to know if p1->p2 or p1->p3 is a leg vs. a hypotenuse.

 

I know you are looking for efficiency, but I would nevertheless include error and undo controls and reseting any changed sysvars.

 

Anyway, I wouldn't get too worried about efficiency.  This is not like creating a digital terrain model from 100,000 points.  What's most important is that it just works.  None of your users will be looking at your code and saying, "Ooh, this code is so verbose that it's giving me a headache."

John F. Uhden

0 Likes
Message 3 of 33

Anonymous
Not applicable

1. Most of the time yes,
2. Yes it would be interesting to have these options.
3. No, they will always be rectangles.
4. No, the distance between P1 and P2
5. I did not understand !!
6. Yes, Polilinnhas closed.


Sorry for the english the translator does not translate correctly.

0 Likes
Message 4 of 33

john.uhden
Mentor
Mentor

Sorry, I meant parallelograms, not trapezoids.  But if they are intended to be rectangles, then you will end up with trapezoids at each end.  If that is allowed, then if each polyline is supposed to be "equal" then what must be equal, the frontage/width or the areas?  Of course that question disappears if we force the right angles.

 

I forgot what #5 was.  Maybe it doesn't matter.

John F. Uhden

0 Likes
Message 5 of 33

Anonymous
Not applicable

The width should be the same.

0 Likes
Message 6 of 33

john.uhden
Mentor
Mentor

Okay.  We are moving right along.

 

Now if  p1, p2, p3 do not form a right angle,  do you want the first polyline to be trapezoidal and the remainder to be rectangular, or do you want them all to be parallelograms?  Do you want the line intersecting at p3 to be parallel to p1->p2 or to be perpendicular to p2->p3?

John F. Uhden

0 Likes
Message 7 of 33

Anonymous
Not applicable

I wish all parallelograms,  p3 to be parallel to p1-> p2

0 Likes
Message 8 of 33

john.uhden
Mentor
Mentor
Accepted solution

I think this will work.  Pardon me.  I am a civil so it looks like we are cutting up parcels

of land to me.  Thus the name.

 

(defun c:Subdivide ( / *error* vars vals p1 p2 p3 p4 ang n w)
  (gc)
  (vl-load-com)
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *doc* (setq *doc* (vla-get-ActiveDocument *acad*)))
  (defun *error* (error)
    (mapcar 'setvar vars vals)
    (vla-endundomark *doc*)
    (cond
      ((not error))
      ((wcmatch (strcase error) "*QUIT*,*CANCEL*"))
      (1 (princ (strcat "\nERROR: " error)))
    )
    (princ)
  )
  (vla-endundomark *doc*)
  (vla-startundomark *doc*)
  (setq vars '("cmdecho" "osmode"))
  (setq vals (mapcar 'getvar vars))
  (mapcar 'setvar vars '(0 0))
  (command "_.expert" (getvar "expert")) ;; dummy command
  (and
    (setq p1 (getpoint "\nP1: "))
    (setq p2 (getpoint p1 "\nP2: "))
    (setq p3 (getpoint p2 "\nP3: "))
    (or
      (not (equal (angle p1 p2)(angle p1 p3) 1e-4))
      (alert "\nPoints are all in a straight line.")
    )
    (not (initget 7))
    (setq n (getint "\nEnter quantity of parcels to create: "))
    (setq ang (angle p2 p3))
    (setq w (/ (distance p2 p3) n))
    (repeat n
      (setq p3 (polar p2 ang w)
                 p4 (polar p1 ang w)
      )
      (vl-cmdf "_.pline" p2 p3 p4 p1 "_C")
      (setq p2 p3 p1 p4)
    )
  )
  (*error* nil)
)
(defun c:SD ()(c:Subdivide))

John F. Uhden

0 Likes
Message 9 of 33

Kent1Cooper
Consultant
Consultant

That's the direction I was inclined to go.  Some thoughts came to mind....

 

It will actually function if the three picked points are in a straight line -- kind of pointless, but there's no reason it can't draw them that way.  Whatever the usage, probably the realities of what they're doing will "prevent" their picking three in line with each other, anyway.

 

A couple of things you can dispense with:  the double-quotes around the System Variable names in the 'vars' list, thus:

 

(setq vars '(cmdecho osmode))

 

and the 1 in the last (cond)ition in the error handler, which can be just:

 

((princ (strcat "\nERROR: " error)))

 

[You need something that does not return nil -- and as I've seen it, most people use T -- as a test if  there's more than one  thing to do as a none-of-the-above operation, but if there's only one, that itself can be the "condition."]

 

For the drawing of the parallelograms, this much:

 

    (repeat n
      (setq p3 (polar p2 ang w)
                 p4 (polar p1 ang w)
      )
      (vl-cmdf "_.pline" p2 p3 p4 p1 "_C")
      (setq p2 p3 p1 p4)
    )

 

can be replaced by this, forgetting about the 'p3' variable and eliminating the need for 'p4' entirely:

 

    (repeat n
      (vl-cmdf "_.pline" p1 p2 (setq p2 (polar p2 ang w)) (setq p1 (polar p1 ang w)) "_close")
    )

Kent Cooper, AIA
0 Likes
Message 10 of 33

trevor.bird.au
Advocate
Advocate

Hi Francisco,

 

I hope my interpretation of what you are looking for assists you.

 

The 3 points required can be selected in any order and a check is made to see if a rectangle can be defined.

 

For testing I've incremented the color of each rectangle and can be removed or commented out.

 

 

Regards,

Trevor

 

;;  3PointRectangle.lsp by Trevor Bird
;;
;;  2018-01-13

;;------------------------------------------------------------------------------
(defun c:3pointrectangle
  (
    /

    color_int

    entlast_dxf
    entlast_ename

    Long:uv
    Long_length

    NumberOfRectangles

    P1P2:uv
    P1P3:uv
    P2P3:uv

    P1ucs
    P1wcs
    P2ucs
    P2wcs
    P3ucs
    P3wcs
    P4ucs
    P4wcs
    ptwcs

    R1ucs
    R1wcs
    R2ucs
    R2wcs
    R3ucs
    R3wcs
    R4ucs
    R4wcs

    Short:uv
    Short_length
    sv_blipmode
    sv_cmdecho
    sv_osmode

    vxv1
    vxv2
    vxv3
    vxv4
  )
  (setq 3pointrectangleErr *error* *error* 3pointrectangle:Error)


  (setq sv_blipmode (getvar 'BLIPMODE))
  (setvar 'BLIPMODE 1)


  (cond
    ( (not (setq P1ucs  (getpoint "\nFirst point (1 of 3): ")))
      (princ "\nFirst point not specified.")
    );(not P1ucs)


    ( (not (setq P2ucs  (getpoint P1ucs "\nSecond point (2 of 3): ")))
      (princ "\nSecond point not specified.")
    );(not P2ucs)


    ( (not (setq P3ucs  (getpoint P2ucs "\nThird point (3 of 3): ")))
      (princ "\nThird point not specified.")
    );(not P3ucs)


    (T
      (setq P1wcs   (trans P1ucs 1 0)
            P2wcs   (trans P2ucs 1 0)
            P3wcs   (trans P3ucs 1 0)

            P1P2:uv (leemac:unit (mapcar '- P2wcs P1wcs))
            P1P3:uv (leemac:unit (mapcar '- P3wcs P1wcs))
            P2P3:uv (leemac:unit (mapcar '- P3wcs P2wcs))

            vxv1    (leemac:vxv P1P2:uv P1P3:uv)
            vxv2    (leemac:vxv P1P2:uv P2P3:uv)
            vxv3    (leemac:vxv P1P3:uv P2P3:uv)
      );setq


      (cond
        ( (and  (not (equal vxv1 0.0 1.0e-4))
                (not (equal vxv2 0.0 1.0e-4))
                (not (equal vxv3 0.0 1.0e-4))
          );and
          ;;  Selected points do not define a rectangle.
          (princ "\nSelected points do not define a rectangle.")
        )


        ( (not
            (progn
              (initget (+ 2 4))
              (setq NumberOfRectangles  (getint "\nNumber of rectangles: "))
            );progn
          );not
          (princ "\nNumber of rectangles not set.")
        )


        (T
          (cond
            ( (equal vxv1 0.0 1.0e-4)
              ;;  P1 is origin of rectangle.
              (setq P4wcs   P3wcs
                    P3wcs   (mapcar '+ P2wcs (leemac:vxs P1P3:uv (distance P1wcs P3wcs)))

                    ;;  Hypotenuse (reset P1P3:uv)
                    P1P3:uv (leemac:unit (mapcar '- P3wcs P1wcs))

                    P3ucs   (trans P3wcs 0 1)
                    P4ucs   (trans P4wcs 0 1)
              );setq
            )


            ( (equal vxv2 0.0 1.0e-4)
              ;;  P2 is origin of rectangle.
              ;;  Reset P1 to P2.
              (setq ptwcs   P1wcs
                    P1wcs   P2wcs
                    P2wcs   ptwcs

                    P1P2:uv (leemac:unit (mapcar '- P2wcs P1wcs))

                    P4wcs   P3wcs
                    P3wcs   (mapcar '+ P2wcs (leemac:vxs P2P3:uv (distance P1wcs P3wcs)))

                    ;;  Hypotenuse (reset P1P3:uv)
                    P1P3:uv (leemac:unit (mapcar '- P3wcs P1wcs))

                    P1ucs   (trans P1wcs 0 1)
                    P2ucs   (trans P2wcs 0 1)
                    P3ucs   (trans P3wcs 0 1)
                    P4ucs   (trans P4wcs 0 1)
              );setq
            )


            ( (equal vxv3 0.0 1.0e-4)
              ;;  P3 is origin of rectangle.
              ;;  Reset P1 to P3.
              (setq ptwcs   P1wcs
                    P1wcs   P3wcs
                    P3wcs   ptwcs

                    P1P2:uv (leemac:unit (mapcar '- P2wcs P1wcs))
                    P1P3:uv (leemac:unit (mapcar '- P3wcs P1wcs))

                    P4wcs   P3wcs
                    P3wcs   (mapcar '+ P2wcs (leemac:vxs P1P3:uv (distance P1wcs P3wcs)))

                    ;;  Hypotenuse (reset P1P3:uv)
                    P1P3:uv (leemac:unit (mapcar '- P3wcs P1wcs))

                    P1ucs   (trans P1wcs 0 1)
                    P3ucs   (trans P3wcs 0 1)
                    P4ucs   (trans P4wcs 0 1)
              );setq
            )
          );cond


          ;;  Determine if rectangle is a square.
          (setq vxv4  (leemac:vxv P1P2:uv P1P3:uv))

          (cond
            ( (< (leemac:acos vxv4) (/ pi 4.0))
              ;;  Hypotenuse is less than 45°.
              ;;  P1.P4 is shortest side.
              (setq Short:uv      (leemac:unit (mapcar '- P4wcs P1wcs))
                    Long:uv       P1P2:uv
                    Short_length  (distance P1wcs P4wcs)
                    Long_length   (distance P1wcs P2wcs)
              );setq
            )

            ( (> (leemac:acos vxv4) (/ pi 4.0))
              ;;  Hypotenuse is greater than 45°.
              ;;  P1.P2 is shortest side.
              (setq Short:uv      P1P2:uv
                    Long:uv       (leemac:unit (mapcar '- P4wcs P1wcs))
                    Short_length  (distance P1wcs P2wcs)
                    Long_length   (distance P1wcs P4wcs)
              );setq
            )

            ( (equal (leemac:acos vxv4) (/ pi 4.0) 1.0e-4)
              ;;  Hypotenuse equals 45°.
              ;;  Square.
              (setq Short:uv      P1P2:uv
                    Long:uv       (leemac:unit (mapcar '- P4wcs P1wcs))
                    Short_length  (distance P1wcs P2wcs)
                    Long_length   (distance P1wcs P4wcs)
              );setq
            )
          );cond


          (setq sv_cmdecho  (getvar 'CMDECHO)
                sv_osmode   (getvar 'OSMODE)
          );setq

          (vlax-invoke-method (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'StartUndoMark)

          (setvar 'CMDECHO 0)
          (setvar 'OSMODE 0)

          (setq R1wcs     P1wcs
                color_int 0
          );setq

          (repeat NumberOfRectangles
            (setq R2wcs (mapcar '+ R1wcs (leemac:vxs Short:uv Short_length))
                  R3wcs (mapcar '+ R2wcs (leemac:vxs Long:uv (/ Long_length NumberOfRectangles)))
                  R4wcs (mapcar '+ R1wcs (leemac:vxs Long:uv (/ Long_length NumberOfRectangles)))

                  R1ucs (trans R1wcs 0 1)
                  R2ucs (trans R2wcs 0 1)
                  R3ucs (trans R3wcs 0 1)
                  R4ucs (trans R4wcs 0 1)
            );setq


            (vl-cmdf "_.PLINE" R1ucs R2ucs R3ucs R4ucs "_C")


            (setq entlast_ename (entlast)
                  entlast_dxf   (entget entlast_ename)
                  color_int     (1+ color_int)
            );setq

            (if (not (assoc 62 entlast_dxf))
              (setq entlast_dxf (append entlast_dxf (list (cons 62 color_int))))
              (setq entlast_dxf (subst (cons 62 color_int) (assoc 62 entlast_dxf) entlast_dxf))
            );if
            (entmod entlast_dxf)
            (entupd entlast_ename)


            ;;  Reset R1wcs
            (setq R1wcs R4wcs)
          );repeat NumberOfRectangles

          (setvar 'CMDECHO sv_cmdecho)
          (setvar 'OSMODE sv_osmode)

          (vlax-invoke-method (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'EndUndoMark)

          (redraw)
        );T
      );cond
    );T
  );cond


  (setvar 'BLIPMODE sv_blipmode)


  (setq *error* 3pointrectangleErr 3pointrectangleErr nil)


  (princ)
);c:3pointrectangle




;;--------------------------------------------------------------------
(defun 3pointrectangle:Error
  ( msg

    /
  )
  (if sv_cmdecho
    (setvar 'CMDECHO sv_cmdecho)
  );if
  (setq sv_cmdecho  nil)


  (if sv_blipmode
    (setvar 'BLIPMODE sv_blipmode)
  );if
  (setq sv_blipmode nil)


  (if sv_osmode
    (setvar 'OSMODE sv_osmode)
  );if
  (setq sv_osmode nil)

  (redraw)

  (vlax-invoke-method (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'EndUndoMark)

  (setq *error* 3pointrectangleErr 3pointrectangleErr nil)
  (princ)
);3pointrectangle:Error




;;------------------------------------------------------------------------------
;; Vector Norm - Lee Mac
;; Args: v - vector in R^n

(defun leemac:norm ( v )
  (sqrt (apply '+ (mapcar '* v v)))
)


;; Vector x Scalar - Lee Mac
;; Args: v - vector in R^n, s - real scalar

(defun leemac:vxs ( v s )
  (mapcar '(lambda ( n ) (* n s)) v)
)


;; Unit Vector - Lee Mac
;; Args: v - vector in R^n

(defun leemac:unit ( v )
  ( (lambda ( n ) (if (equal 0.0 n 1e-14) nil (leemac:vxs v (/ 1.0 n)))) (leemac:norm v))
)


;; Vector Dot Product  -  Lee Mac
;; Args: u,v - vectors in R^n

(defun leemac:vxv ( u v )
    (apply '+ (mapcar '* u v))
)


;; ArcCosine  -  Lee Mac
;; Args: -1 <= x <= 1

(defun leemac:acos ( x )
    (if (<= -1.0 x 1.0)
        (atan (sqrt (- 1.0 (* x x))) x)
    )
)




;;------------------------------------------------------------------------------
(princ "\n3PointRectangle loaded. Start command with 3POINTRECTANGLE.")
(princ)

 

0 Likes
Message 11 of 33

Moshe-A
Mentor
Mentor
Accepted solution

Frjuniornogueira,

 

check this budy...

 

the following is a simple (but yet very neat)  autolisp code to do your polylines boxes (rectangles)

it will work in any angle and support ucs

 

after you pick the first two points (grdraw) will draw a virtual line (on screen only) between and at the end will erase it

if you cancel the program in middle, this virtual line will vanish after a redraw or regen.

 

in order to correct the right angle (90 degrees) between 1st point and the 3rd point two constant variables MIN_ANG_DGRS and MAX_ANG_DGRS are defined (to maintain allowed digression ) and set to 80 degress and 100 degress respectively which means only 10 degress digression is allowed when specifiying the 3rd point. if you want to wider this: say 15 degrees then you should change this values.

if user specifies 3rd point outside this digression, the program will note that and loop to let user specify another 3d point.

 

if distance between 1st point and 2nd point is longer then 2nd point and 3rd point, the program will align the boxes along the 1st and 2nd points.

 

hope you will learn autolisp from it.

 

cheers

Moshe

 

 

(vl-load-com); install ActiveX

(defun C:BOXES (/ ucs2wcs wcs2ucs subtract_angles angle_digression increase_angle 	     ; local functions and procedures
		  ask_boxes swap_points determine_right_angle draw_boxes  	    	     ; local functions and procedures
	          MIN_ANG_DGRS MAX_ANG_DGRS ANG_FUZZ p0 p1 p2 p3 items ang0 ang1 ang2 flag)  ; local variables	
  
 (defun ucs2wcs (pt)
  (trans pt 1 0)
 )
  
 (defun wcs2ucs (pt)
  (trans pt 0 1)
 )
  
 ; subtract angles
 (defun subtract_angles (a0 a1 / a2)
  (if (> a0 a1)
   (setq a2 (- a0 a1))
   (setq a2 (- a1 a0))
  )

  (if (equal a2 (* pi 2) ANG_FUZZ)
   (setq a2 0.0)
   a2
  ) 
 ); subtract_angles


 ; return T if angle digression is no more then 10 degrees
 (defun angle_digression (a0 a1 / a2)
  (setq a2 (subtract_angles a0 a1))
   
  (if (> a2 pi)
   (setq a2 (- (* pi 2) a2))
  )
   
  (and
   (>= a2 MIN_ANG_DGRS) ; min angle digression
   (<= a2 MAX_ANG_DGRS) ; max angle digression
  )
 ); angle_digression   

  
 ; increase a0 with 90 degrees
 (defun increase_angle (a0 amount / a1)
  (setq a1 (+ a0 amount))

  (cond
   ((and
      (equal a0 (* (/ pi 2) 3) ANG_FUZZ); 270
      (equal a1 0.0 ANG_FUZZ)	    	; 0
    )
    (* pi 2)	; return 360
   ); case
   ( t   
    (if (> a1 (* pi 2))
     (- a1 (* pi 2))
     a1
    )
   ); case
  ); cond
 ); increase_angle

  
 ; enter number boxes 
 (defun ask_boxes (msg def / ask)
  (initget (+ 2 4))
  (if (not (setq ask (getint (strcat "\n" msg "(---) <" (rtos def 2 0) ">: "))))
   (setq ask def)
   (setq def ask)
  )
 ); ask_boxes

  
 ; if distance p0->p1 is longer than p1->p2 then swap points
 (defun swap_points (/ tmp p3)
  (if (> (distance p1 p0) (distance p1 p2))
   (progn
    (determine_right_angle)     
    (setq tmp p0)
    (setq p0 p2)
    (setq p2 tmp)
    (setq ang0 (angle p1 p0))
    (setq ang1 (angle p1 p2))
   ); progn
  ); if
 ); swap_points


 (defun determine_right_angle ()
  ; p2 must form right-angle(90) respect to p0 
  (setq p3 (polar p1 (increase_angle ang0 (/ pi 2)) (distance p1 p2)))
  (setq ang2 (angle p1 p3))
   
  (if (> (subtract_angles ang1 ang2) (/ pi 2))
   (progn
    (setq ang1 (increase_angle ang0 (* (/ pi 2) 3)))
    (setq p2 (polar p1 ang1 (distance p1 p2)))       
   ); progn
   (progn
    (setq ang1 ang2)
    (setq p2 p3)
   )
  ); if
 ); detemine_right_angle


 (defun draw_boxes (/ ax)
  (setq ax (/ (distance p1 p2) items))
  (setq p2 (polar p1 ang1 ax))
  (setq p3 (polar p0 ang1 ax))
 
  (repeat items
   (command ".pline" (wcs2ucs p0) (wcs2ucs p1) (wcs2ucs p2) (wcs2ucs p3) "close")
   (setq p0 p3 p1 p2)
   (setq p2 (polar p1 ang1 ax))
   (setq p3 (polar p0 ang1 ax))
  ); repeat
 ); draw_boxes

  
 ; here start C:BOXES command
 (setvar "cmdecho" 0)	; disable command echo
 (command ".undo" "begin")

 ; const
 (setq ANG_FUZZ 0.00001)
 ; mix & max angle digression
 (setq MIN_ANG_DGRS (* (/ pi 18) 8))  ;  80 degrees
 (setq MAX_ANG_DGRS (* (/ pi 18) 10)) ; 100 degrees
	
 ; set default items
 (if (= (getvar "useri5") 0)
  (setvar "useri5" 1)
 )
	
 (if (and
       (setvar "useri5" (setq items (ask_boxes "Enter the number of boxes" (getvar "useri5"))))
       (setq p0 (getpoint    "\nSpecify 1st point: "))
       (setq p1 (getpoint p0 "\nSpecify 2nd point: "))
       (not (grdraw p0 p1 -7)) ; draw virtual vector
       (setq p2 (getpoint p1 "\nSpecify 3th point: "))
     )
  (progn
   ; transfer all coordibates to WCS
   (setq p0 (ucs2wcs p0))
   (setq p1 (ucs2wcs p1))
   (setq p2 (ucs2wcs p2))
   
   (setq ang0 (angle p1 p0))
   (setq ang1 (angle p1 p2))

   ; p2 must form right-angle respect to p0 
   (while (and p2
	       (not (setq flag (angle_digression ang0 ang1)))
	  )
    (vlr-beep-reaction)
    (prompt "\n3th point doesn't form right-angle with 1st point, try again...")
     
    (if (setq p2 (getpoint p1 "\nSpecify 3th point: "))
     (progn
      (setq p2 (ucs2wcs p2))
      (setq ang1 (angle p1 p2))
     )
    )
   ); while
   
   ; continue, if right-angle is formed?
   (if flag
    (progn
     (grdraw (wcs2ucs p0) (wcs2ucs p1) -7) ; clear virtual vector
     (swap_points)
     (determine_right_angle)
     (draw_boxes)
    ); progn
   ); if
  ); progn
 ); if

 (command ".undo" "end")
 (setvar "cmdecho" 1) ; restore command echo
  
 (princ)
); c:boxes
0 Likes
Message 12 of 33

Anonymous
Not applicable

It was exactly as I was thinking, sensational !!! It will help me a lot. I do not know how to thank you, thank you very much!

0 Likes
Message 13 of 33

Anonymous
Not applicable

@john.uhden It was exactly as I was thinking, sensational !!! It will help me a lot. I do not know how to thank you, thank you very much!

0 Likes
Message 14 of 33

Anonymous
Not applicable

@Moshe-A Very good too !!! thank you. You and the others helped.

0 Likes
Message 15 of 33

john.uhden
Mentor
Mentor

Thank you, Kent.  If you keep it up I will be writing one-liners.

 

I learned to use 1 instead of T because some other software just might (setq T nil) but you can't (setq 1 nil).

John F. Uhden

0 Likes
Message 16 of 33

john.uhden
Mentor
Mentor

You can show your thanks by hanging around here, learning, and then being one of the helpers.

Somebody has to be here for when we old farts fade away.

John F. Uhden

0 Likes
Message 17 of 33

ActivistInvestor
Mentor
Mentor

@Moshe-A wrote:

 

Specify 3th point:
3th point doesn't form right-angle with 1st point, try again...

I don't understand.

 

If you already have two points representing one side of a rectangle, then you only need a point on the line passing through the opposite side, because the point only defines the direction and distance to the other side, so what's the purpose of requiring a point that forms a right angle with the side defined by the first two points?

 

I think any point should be accepted as the third point, so long as it's not colinear with the first two points.

 

 

 

0 Likes
Message 18 of 33

john.uhden
Mentor
Mentor
But if the 2th point is the same as the 1th point then there is no angle to
which to be perpendicular or anything.
That is a condition of which I did not cover. Or maybe we would be
creating paranilograms?

John F. Uhden

0 Likes
Message 19 of 33

ActivistInvestor
Mentor
Mentor

@john.uhden wrote:
But if the 2th point is the same as the 1th point then there is no angle to
which to be perpendicular or anything.


I think that's just erroneous input that needs to be checked. My comment was mainly about needless, over-constrained input, which limits a user's ability to do things like use osnap to align the other side of the rectangle with a known point.

 

Although, perhaps my comment/question should be directed at the OP rather than @Moshe-A.

0 Likes
Message 20 of 33

Moshe-A
Mentor
Mentor

Hi,

 

Yes you are right i admit we little 'carried away' after the OP but on second thought if the distance of the first segment is longer than the first segment then the rectangles are aligned to the second segment and the 3rd point become more significant.

 

i challage the OP to write a fix. i'll also would be glade to 'hear' if you  have some good things to say on the code.

 

thank you

Moshe

 

0 Likes