Jump to content

Quadrants of a circle in a unique UCS


kapat

Recommended Posts

Hello guys.

I've been trying to keep up with all the lisps I can understand, and I've been getting better at it. so much so, I've written a few without any help!

 

But alas, I was bound for failure sooner or later. So I have come crawling back.

 

I have written this little lisp. i'm sure there are like 50 different versions of, it's to make a 3 point circle within those 3 point's UCS, without having to change UCS manually.

 

shown here:

 


;	3 point circle maker!!!!
;	11/06/13
;	Patrick Mitchell
;	kapatrick@gmail.com
; picks 3 points, makes those their own UCS and makes a circle in 1 easy step!
;
;

(defun c:3PC (/ p1 p2 p3 wp1 wp2 wp3)
(while ;start while

(setq p1 (getpoint "point1"))
(setq p2 (getpoint "point2"))
(setq p3 (getpoint "point3"))

(setq wp1 (trans p1 1 0))
(setq wp2 (trans p2 1 0))
(setq wp3 (trans p3 1 0))

(command "_ucs" "3p" p1 p2 p3)

(command "CIRCLE" "3P" (trans wp1 0 1) (trans wp2 0 1) (trans wp3 0 1))
(command "._ucs" "_w")

(princ)
) ;end while
)

 

(side note: I couldn't get "entmake" to work in this way. For some reason I couldn't get the DXF code and the "trans 0 1" to work. I usally like to use entmake so I can name my circles and lines and refer back to them.)

 

Now, here is where it get tricky. Cause I want to "improve" it, but very specifically.

 

Most this code I need works with "assoc" and "mapcar" I think.

 

What I am looking for is a way for when I create these circles, i'm looking for the quadrants of these circles, but in WCS. From what I suspect, this might be impossible. Because when you're in WCS, you can't pick quadrants of circles that are made within a unique UCS. So far i've been having to fake it out by creating a circle next to it, and rotate some quadrant lines in reference to my perfect circle.

 

Any ideas? or I would appreciate somebody to tell me it's impossible, so I don't go chasing a pipe dream for 2 weeks.

 

Thanks for your time!

Link to comment
Share on other sites

The following example should perform correctly in all UCS & Views:

 

([color=BLUE]defun[/color] c:3pc ( [color=BLUE]/[/color] cn cr nv p1 p2 p3 rd )
   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] p1 ([color=BLUE]getpoint[/color] [color=MAROON]"\n1st point: "[/color]))
           ([color=BLUE]setq[/color] p2 ([color=BLUE]getpoint[/color] [color=MAROON]"\n2nd point: "[/color] p1))
           ([color=BLUE]setq[/color] p3 ([color=BLUE]getpoint[/color] [color=MAROON]"\n3rd point: "[/color] p2))
       )
       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] cr (LM:3PCircle p1 p2 p3))
           ([color=BLUE]progn[/color]
               ([color=BLUE]setq[/color] nv ([color=BLUE]trans[/color] '(0.0 0.0 1.0) 1 0 [color=BLUE]t[/color])
                     cn ([color=BLUE]trans[/color] ([color=BLUE]car[/color] cr) 1 nv)
                     rd ([color=BLUE]cadr[/color] cr)
               )
               ([color=BLUE]entmake[/color]
                   ([color=BLUE]list[/color]
                      '(0 . [color=MAROON]"CIRCLE"[/color])
                       ([color=BLUE]cons[/color] 010 cn)
                       ([color=BLUE]cons[/color] 040 rd)
                       ([color=BLUE]cons[/color] 210 nv)
                   )
               )
               ([color=BLUE]foreach[/color] x
                   ([color=BLUE]list[/color]
                       ([color=BLUE]list[/color] rd 0.0 0.0)
                       ([color=BLUE]list[/color] 0.0 rd 0.0)
                       ([color=BLUE]list[/color] ([color=BLUE]-[/color] rd) 0.0 0.0)
                       ([color=BLUE]list[/color] 0.0 ([color=BLUE]-[/color] rd) 0.0)
                   )
                   ([color=BLUE]entmake[/color]
                       ([color=BLUE]list[/color]
                          '(0 . [color=MAROON]"POINT"[/color])
                           ([color=BLUE]cons[/color] 010 ([color=BLUE]trans[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] cn x) nv 0))
                           ([color=BLUE]cons[/color] 210 nv)
                       )
                   )
               )
           )
           ([color=BLUE]princ[/color] [color=MAROON]"\nPoints are collinear."[/color])
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; 3-Point Circle  -  Lee Mac[/color]
[color=GREEN];; Returns the Center and Radius of the Circle defined by the supplied three points.[/color]

([color=BLUE]defun[/color] LM:3PCircle ( p1 p2 p3 [color=BLUE]/[/color] a b c d )
   ([color=BLUE]setq[/color] p2 ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] p2 p1)
         p3 ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] p3 p1)
         a  ([color=BLUE]*[/color] 2.0 ([color=BLUE]-[/color] ([color=BLUE]*[/color] ([color=BLUE]car[/color] p2) ([color=BLUE]cadr[/color] p3)) ([color=BLUE]*[/color] ([color=BLUE]cadr[/color] p2) ([color=BLUE]car[/color] p3))))
         b  ([color=BLUE]distance[/color] '(0.0 0.0) p2)
         c  ([color=BLUE]distance[/color] '(0.0 0.0) p3)
         b  ([color=BLUE]*[/color] b b)
         c  ([color=BLUE]*[/color] c c)
   )
   ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]equal[/color] 0.0 a 1e-)
       ([color=BLUE]list[/color]
           ([color=BLUE]setq[/color] d
               ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] p1
                   ([color=BLUE]list[/color]
                       ([color=BLUE]/[/color] ([color=BLUE]-[/color] ([color=BLUE]*[/color] ([color=BLUE]cadr[/color] p3) b) ([color=BLUE]*[/color] ([color=BLUE]cadr[/color] p2) c)) a)
                       ([color=BLUE]/[/color] ([color=BLUE]-[/color] ([color=BLUE]*[/color] ([color=BLUE]car[/color]  p2) c) ([color=BLUE]*[/color] ([color=BLUE]car[/color]  p3) b)) a)
                       0.0
                   )
               )
           )
           ([color=BLUE]distance[/color] d p1)
       )
   )
)

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