Jump to content

Recommended Posts

Posted

I'm looking for a simple routine that completes a square given 3 points.

 

The only condition is of course that the opposite sides are equal in length and parallel.

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    8

  • lpseifert

    7

  • therock005

    4

  • Lee Mac

    3

Top Posters In This Topic

Posted

Just how do the 3 points relate to the square? Corners?

A square by definition has 4 sides of equal length with 4 interior angles of 90 degrees. this may not be possible given 3 points.

It might be clearer if you were to post an example.

Posted

Sorry i didint mean a perfect sqaure with equal all 4 sides and right angles. I meant a 4 sided polygon, with opposite sides equal and parallel (no matter what the angles may be).

 

EDIT: Ok and just so there's no confusion here's what i mean. Here are 3 points and here's the part you supposedly create by joing them. The line in red is the missing part that should be filled. So this routine should create this 4 sided polygon given you supply the 3 points in the correct order.

 

20aoz2r.jpg

Posted

here's a quickey...

I hope you study and try to learn from it.

(defun c:test (/ oldsnap pt1 pt2 pt3)
 (setq oldsnap (getvar "osmode"))
 (setvar "osmode" 0)
 (setq pt1 (getpoint "\nPick 1st point: ")
   pt2 (getpoint pt1 "\nPick 2nd point: ")
   pt3 (getpoint pt2 "\nPick 3rd point: "))
 (entmake
   (list
     (cons 0   "LWPOLYLINE")
     (cons 100 "AcDbEntity")
     (cons 100 "AcDbPolyline")
     (cons 90 4)
     (cons 70 1)
     (cons 10 pt1)
     (cons 10 pt2)
     (cons 10 pt3)
     (cons 10 (polar pt3 (angle pt2 pt1)(distance pt2 pt1)))
     )
   )
 (setvar "osmode" oldsnap)
 (princ)
 )

Posted

Good stuff Larry, but why'd you turn the OSnaps off? They don't have an affect entmake.

Posted

Force of habit I guess...

I figured that osnap might affect the getpoint

Posted
Force of habit I guess...

I figured that osnap might affect the getpoint

OSnaps on for getpoint are fine. If not, you wouldn't be able to snap to anything.

Posted

Let me re-phrase...

I figured that using a running osnap might return an unintentional point

(99% of the time I leave osnaps off, and use the keyboard/toolbar as needed)

Posted
Let me re-phrase...

I figured that using a running osnap might return an unintentional point

It wouldn't hurt what you posted. Actually, as long as you placed "_non" before each point, you could have used command (not that I'm suggesting that) and it wouldn't have hurt anything.

 

(99% of the time I leave osnaps off, and use the keyboard/toolbar as needed)

Same here.

Posted
you could have used command

No no... I'm afraid Lee Mac would whack me across the knuckles if I tried that.

(just joking)

Posted

Works great but as the others noted it disables my osnaps. :(

 

Is it possible to temporarily enable the node osnap just for this action and when the command finishes to rest to the previous state of osnaps?

Posted

done, i found the node code was 8 from another topic so instead o zero i made it 8 and it now works as i wanted.

 

Thank You man, i appreciate it. :)

 

EDIT: It seems that you edited your message and pointed it out, but it's ok i did a little searching as well and came up with the answer. :)

Posted

I'd just take out all the OSMode toggling code out.

Posted
Artistic license

LoL

Works for me. :)

 

[undocumented feature]

Posted
No no... I'm afraid Lee Mac would whack me across the knuckles if I tried that.

 

And so you should be ... :P

Posted

No OSnap on last pick, but just for the fun of it:

 

(defun c:sq ( / LWPoly RemoveIfOdd GR I LST P P1 P2 P3 P4 )
 (vl-load-com)
 ;; Lee Mac  ~  26.04.10

 (defun LWPoly ( lst cls )
   (entmakex (append (list (cons 0 "LWPOLYLINE")
                           (cons 100 "AcDbEntity")
                           (cons 100 "AcDbPolyline")
                           (cons 90 (length lst))
                           (cons 70 cls))
                     (mapcar (function (lambda (p) (cons 10 p))) lst))))

 (defun RemoveIfOdd ( lst )
   (  (lambda ( i )
        (vl-remove-if
          (function
            (lambda ( x ) (= 1 (boole 1 1 (setq i (1+ i)))))) lst)) -1))

 (if (and (setq p1 (getpoint "\nPick First Point:  "))
          (setq p2 (getpoint "\nPick Second Point: " p1)))
   (progn
     (while (and (= 5 (car (setq gr (grread t 13 0))))
                 (listp (setq p3 (cadr gr))))
       (redraw)
       (setq p4 (polar p3 (angle p2 p1) (distance p1 p2)))

       (grvecs (cons -3 (setq p (list p1 p2 p2 p3 p3 p4 p4 p1)))))

     (LWPoly (RemoveIfOdd (cdr p)) 1) (redraw)))
     
 (princ))

Posted
And so you should be ... :P

:roll:.

......................

Posted
No OSnap on last pick, but just for the fun of it:

Nice coding. :)

Such a shame the third pick doesn't have OSnap capabilities. GrRead's lack of OSnap functionality makes it almost useless.

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