Author Topic: square to circle lisp  (Read 15203 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
square to circle lisp
« Reply #15 on: June 11, 2004, 08:19:59 PM »
Quote from: CAB
Code: [Select]
(40 100 101 102 117 110 32 99 58 115 113 50 99 105 114 99 108 101 32 40 41)
(32 32 59 59 114 101 116 117 114 110 58 32 84 32 105 102 32 99 108 111 115 101 100 44 32 110 105 108 32 111 116 104 101 114 119 105 115 101)
(32 32 40 100 101 102 117 110 32 105 115 112 111 108 121 99 108 111 115 101 100 32 40 101 108 105 115 116 41)
(32 32 32 32 40 61 32 49 32 40 108 111 103 97 110 100 32 49 32 40 99 100 114 32 40 97 115 115 111 99 32 55 48 32 40 101 110 116 103 101 116 32 101 108 105 115 116 41 41 41 41 41)
(32 32 41)
...
(41)

Code: [Select]

(defun c:sq2circle ()
  ;;return: T if closed, nil otherwise
  (defun ispolyclosed (elist)
    (= 1 (logand 1 (cdr (assoc 70 (entget elist)))))
  )  
  ...
)
I don't get it, was this a quiz or something?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
square to circle lisp
« Reply #16 on: June 11, 2004, 08:35:13 PM »
Well you do get it. :)
But I was just goofing around.
Stig & Se7en were trying to get some of the folks that are new to
lisp to practice with this task of making a square into a circle
but I couldn't wait so I posted my homework in code so to speak.
But you already new that too. :)

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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
square to circle lisp
« Reply #17 on: June 11, 2004, 11:31:07 PM »
My rule is "if the question is ambiguous, anything goes"
so ..  :
Code: [Select]

Command:
POLYGON Enter number of sides <4>:

Specify center of polygon or [Edge]: _CEN of
Enter an option [Inscribed in circle/Circumscribed about circle] <I>: C

Specify radius of circle: _QUA of
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.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
square to circle lisp
« Reply #18 on: June 12, 2004, 01:57:05 AM »
Very elegant and simple, Kerry
I drink beer and I know things....

SMadsen

  • Guest
square to circle lisp
« Reply #19 on: June 12, 2004, 08:05:27 AM »
What I was trying to say is only that a simple task like this could be used to get to a point where it might be more interesting to request information on how to solve tasks instead of finished solutions.

CAB and Se7en, while it would be an honour to start a session for beginners, I don't think neither of you would fit the category :)

rude dog

  • Guest
square to circle lisp
« Reply #20 on: June 12, 2004, 08:13:12 AM »
needs some error checking but this is how a total green horn would do it ......
hey thats me:  :( ........damn
Code: [Select]

(defun c:stc (/ sc)
(command "cmdecho" "0")
(prompt "\npick squares to change to circles ")
(command "select" pause "") (setq sc (ssget "p"))
(command "pedit" "m" sc "" "f" "")
)
(princ)

not sure what all the numbers are If I had to guess I would say the ASCII
function would clear things up...just a guess but I didnt try it.

SMadsen

  • Guest
square to circle lisp
« Reply #21 on: June 12, 2004, 08:43:41 AM »
Rude dog, excellent try but it doesn't meet the initial requirement: "... will change a square to a circle". It merely makes an arc-fitted pline.

That the final entity be a circle is actually the only requirement given - all the rest needs to be defined. T-bear mentioned some of the variables that need to be determined: should the circle have the same area, the same perimeter or what? The next question could be: What is a square? Is it a closed pline only? Is it open plines? Regions? Faces?
Should properties be transferred? What about coordinate transformation?

All questions that make it a good exercise.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
square to circle lisp
« Reply #22 on: June 12, 2004, 08:58:47 AM »
rude dog,
That is a nice solution and works well or squares although rectangles
turn to flat ovals. Which may not be a bad thing either. But as Stig said
does not meet the requirement.

Try this for the selection set get. You can have the user acquire the
selection set via the ssget command and still filter the set.

For more info the best source is Smadsem's site
Look under "Selections" it is very good reading.

Code: [Select]
 (prompt "\npick squares to change to circles ")
  (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
    (command "pedit" "m" ss "" "f" "")
  )

 
Didn't mean to but in Stig, I was already finished typing when I saw your post.
 
  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.

rude dog

  • Guest
square to circle lisp
« Reply #23 on: June 12, 2004, 09:02:52 AM »
gotcha...well I guess I mean you guys got me... :x ...when stig ripped the wool away from my eyes I see what was meant....what appears to be a circle really isnt a circle entity....plus all the other stuff that stig mentioned....very very intresting....hope you guys got the taste of blood you where looking for
hey when do I get to taste a little blood besides my own....probably not on this forum.....

rude dog

  • Guest
square to circle lisp
« Reply #24 on: June 12, 2004, 09:08:13 AM »
Thanks CAB
I have not tried using a filtered ss yet....thanks I must read on

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
square to circle lisp
« Reply #25 on: June 12, 2004, 09:21:40 AM »
rude dog

Quote from: Smadsen
Rude dog, excellent try but it doesn't meet the initial requirement: "...


He praised your efforts as did I.
No blood letting was intended, merely to focus your efforts on the given task.
In my opinion defining the problem can be the most tricky part of the project.
Once you know exactly what the parameters are you can quickly fashion a solution
in pseudo code that is. It still take me some time to convert the pseudo code into
lisp because I am still learning the language.

Please don't take offense by comments only meant to help you,
Uh unless there are from Se7en. :)
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.

rude dog

  • Guest
square to circle lisp
« Reply #26 on: June 12, 2004, 10:09:15 AM »
never once on this sight have I felt even close to being offended
I was just trying to poke fun @ myself..my best quality probably is my sense of humor....obviously not my lisping ...man there I go again
 :D

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
square to circle lisp
« Reply #27 on: June 12, 2004, 10:21:42 AM »
Boy, you sure are good at that. :)
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
square to circle lisp
« Reply #28 on: June 12, 2004, 10:55:00 AM »
Speaking of "Defining the Problem" I always miss some things that are later
pointed out by a user with a different approach. Take t-bear who though about
the perimeter of the circle being equal to the square or maybe the area.
It never occurred to me. Then Kerry who thinks outside the box suggested polygons
with more sides that 4. In this case dan asked for a circle from a square.
Well for me the first thing I though of was the RECTANGLE command which creates
4 sided LWPOLYLINES and I use it to make squares with @36,36 from the command
line. Because Dan said SQUARE instead of RECTANGLE that could be a requirement.
He may have meant RECTANGLE but he said SQUARE. I chose to use rectangles in my
solution. Which you can use (vl-list->string *list* ) to convert.

So I defined the problem this way:

User select pline object
test object, 4 sided LWPOLYLINE
...  left out test for rectangle and parallelogram
derive the center point
derive the radius
...  used a hard code variable to switch between 3 options
...  radius = end points of rectangle
...  radius = closest side of rectangle
...  radius = farthest side of rectangle
...  other options were "average" by Se7en
...  Perimeter & area by t-bear
entmake the circle using layer, linetype & color from square
erase the square
done

As you see from Smadsen's post there are other things to consider.
Error handling & checking can consume large amounts of code & time
but because my routines are for me & without compensation $$ I only do
a minimum of error checking & often leave out the error handler.

So if someone wanted to attempt the coding of the problem I think Smadsen
could be talked into guiding the process. I know I learn something on
any of his contributions. And my pseudo code will have to be ammended as well.

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.

confusedCADguy

  • Guest
square to circle lisp
« Reply #29 on: July 28, 2004, 06:28:02 PM »
Has anyone had any luck with this.  I just finished a foundation plan with spread footings under each column and the engineer walked by and said "you know those need to be on piers right?"  AAAARRRRGGGHHHH!!!!!!!!!  So...if anyone has something that converts a square to a circle I could really use it.  An example of how it would work is converting a 4'-0"X4'-0" square footing to a 4'-0" dia pier.

Any help is greatly appreciated