TO ARRANGE DIFFERENT SIZE SMALL CIRCLES INSIDE A BIG CIRCLE

TO ARRANGE DIFFERENT SIZE SMALL CIRCLES INSIDE A BIG CIRCLE

arpansark0544TCX
Advocate Advocate
1,212 Views
9 Replies
Message 1 of 10

TO ARRANGE DIFFERENT SIZE SMALL CIRCLES INSIDE A BIG CIRCLE

arpansark0544TCX
Advocate
Advocate

HELLO,

IS THE A LISP TO ARRANGE DIFFERENT SIZE SMALL CIRCLES INSIDE A BIG CIRCLE.

SUCH THAT THEY ARE NOT OVERLAPPING. AND TAKING THE LEAST POSSIBLE AREA.

LISP SHOULD ASK US TO SELECT ALL THE SMALL CIRCLES AND THEN ARRANGE THEM INSIDE THE BIG CIRCLE FORMED BY THE SMALL CIRCLES.

 

THANK YOU FOR YOUR HELP IN ADVANCE.

 

arpansark0544TCX_0-1646923258283.png

 

0 Likes
1,213 Views
9 Replies
Replies (9)
Message 2 of 10

leeminardi
Mentor
Mentor

Would you be interested in a VLISP program that allowed you to easily move a circle so that it is tangent to two other circles?  This would simplify the process of manually arranging the circles.

lee.minardi
Message 3 of 10

john.uhden
Mentor
Mentor

@leeminardi 

Nice try, Lee.  I think he wants to avoid the word "manually" altogether, so have fun trying to "programmatically" position them yourself.

Yes, the old arc-arc-intersect method is needed , but there are two answers for that, the trick being to pick the right one every time.

John F. Uhden

Message 4 of 10

leeminardi
Mentor
Mentor

@john.uhden Let's see what the OP says regarding a manual method with better tools.  As for which intersection of the two circle to choose a numerical solution allows you to easily set a bias point.  I think the current location of the circle would provide a good starting guess.

lee.minardi
Message 5 of 10

john.uhden
Mentor
Mentor

@leeminardi wrote, "... the current location of the circle would provide a good starting guess."

You have reminded me of poor old Frank at the pool liner plant.  He was assigned to make a new 8' diam. table top for the rotating tables they use to seam the liner panels.  Bobby, the owner, had laid out the curve using 8 octants so it would be perfectly round.  But he also drew the chords as a double check on his on work.

Well, Frank successfully joined the two 4'x8' sheets and started cutting... along the chords!!!  I had walked out to the other building where he was and just couldn't resist... "Hey Frank, how many sides does a circle have?"

 

So, Lee, on which "side" of the circle will you start?

John F. Uhden

0 Likes
Message 6 of 10

leeminardi
Mentor
Mentor

So, Lee, on which "side" of the circle will you start?

 

@john.uhden,  The short answer?  The inside!

 

In my effort to be brief I guess I was not clear enough. 

 

I was thinking that the user could start by positioning one circle (red) inside and tangent to the large circle. He/she/they could then position the next circle (yellow) inside the large circle near to where they want its final position. For example,

leeminardi_0-1647467540947.png

The program would prompt the user to select the circle to be moved and then the two circles to which it should be tangent. Of the two solutions A & B for the circle's center, the program would choose B in this case as it is closer to the original position of the circle.  The process could be quickly repeated for successive circles.

leeminardi_1-1647468018376.png

 

Now John, since you are a world class sailor, you'll have to tell me if that is the starboard or port side?

 

 

lee.minardi
Message 7 of 10

john.uhden
Mentor
Mentor

@leeminardi 

Good answer, Lee!

Starboard, shmarboard.  You just start shouting "Buoy Room!" and hope the other dolt falls for it.  If he doesn't you run him over, break his side stay and he protests you out of the race leaving you ample time to pack up the boat and hit the bar.  After being 5 minutes late for the start you weren't gonna win anyway.  Almost all the clubs on Barnegat Bay enable support drinking.  Actually, my best man Bob and I were late every Saturday morning (something to do with Friday nights?) yet we would still come in 4th in the summer series with 50 boats in our class.

Had we ever been serious we coulda won some serious hardware, though we did often win the special regattas.  But we just wanted to have fun.  Nothing has changed very much.

Gotta hand it to you; there's always a method to your madness.

John F. Uhden

0 Likes
Message 8 of 10

leeminardi
Mentor
Mentor

@arpansark0544TCX   the program below will not automatically arrange the circles but should enable you to easily move a circle so that it tangent to one or two other circles.

Execute the cirtangent command and then select the circle you want to move followed by selecting one or two other circles. The start position of the circle to be moved determines to which side (inside/outside, left/right, up/down...) the circle will be positioned.

 

The program uses a numerical solution (trial and error) to locate the position.  Several tests indicate that it converges very quickly to a specified tolerance which is set at 0.0001.  This tolerance could be modified if necessary. I've done limited testing so let me know if you find a problem.

 

Lee

 

Before and after

leeminardi_0-1647625817590.png

 

(defun c:cirtangent (/ ss circle1 r1 cen1 circle2 r2 cen2 uc2c1 t1 ut1c1 newcen1 circle3 r3 cen3 rA cenA
	      rB cenB biaspt newcen1) ;  circle circle tangent
  (setvar "osmode" 0)
  (princ
    "\n Select the circle you want to move first,")
  (princ "\nthen one or two circles to be tangent."
  )
  (if (setq ss (ssget '((0 . "CIRCLE"))))
    (progn
      (setq circle1 (vlax-ename->vla-object (ssname ss 0))
      )
      (setq cen1 (vlax-get circle1 'center)
	    r1	 (vlax-get circle1 'radius)
      )
      (setq circle2 (vlax-ename->vla-object (ssname ss 1))
      )
      (setq cen2 (vlax-get circle2 'center)
	    r2	 (vlax-get circle2 'radius)
      )
      
      (if (< (sslength ss) 3)
	(progn				; case when 2 circles selected 
	  (setq uc2c1 (uvec cen2 cen1))
	  (setq t1 (mapcar '+ cen2 (mapcar '* uc2c1 (list r2 r2 r2))))
	  (setq ut1c1 (uvec t1 cen1))
	  (setq
	    newcen1 (mapcar '+ t1 (mapcar '* ut1c1 (list r1 r1 r1)))
	  )
	  (vla-put-center
	    circle1
	    (vlax-3d-point newcen1)
	  )
	)				
	(progn				; case when more than 2 circles selected
	  (setq	circle3	(vlax-ename->vla-object (ssname ss 2))
	  )
	  (setq	cen3 (vlax-get circle3 'center)
		r3   (vlax-get circle3 'radius)
	  )
	  (if (< (distance cen1 cen2) r2)
	    (setq rA (- r2 r1))
	    (setq ra (+ r2 r1))
	  )
	  (setq cenA cen2)
	  (if (< (distance cen1 cen3) r3)
	    (setq rB (- r3 r1))
	    (setq rB (+ r3 r1))
	  )
	  (setq cenB cen3)
	  (setq biaspt cen1)
	  (setq newcen1 (circleintr cenA rA cenB rB biaspt))
	  (if newcen1
	    (progn
	      (vla-put-center
		circle1
		(vlax-3d-point newcen1)
	      )
	    )
	    (princ "\nNo solution!")
	  )
	)				;end progn more than 2 circles selected
      )
    )					; end progn selection set
  )
  (princ)
)
; calculate unit vector from v1 to v2
(defun uvec (v1 v2 / s)
  (setq s (distance v1 v2))
  (setq s (mapcar '/ (mapcar '- v2 v1) (list s s s)))
)

; calculate the intersection point of two circles that is
; closest to a bias point.
(defun circleintr (cenA rA cenB rB biaspt / tol uA guess1 uB guess2 d i ans)
  (setq tol 0.0001) ; set tolerance for intersection point
  (setq	uA (uvec cenA biaspt)
	guess1 (mapcar '+ cenA (mapcar '* uA (list rA ra rA)))
	uB (uvec cenB guess1)
  )
  (setq	guess2
	 (mapcar '+ cenB (mapcar '* uB (list rB rB rB)))
  )
  (setq d (distance guess1 guess2))
  (setq i 0)
  (while (and (> d tol) (< i 21)) ; limit to 20 iterations
    (setq uA (uvec cenA guess2)
	  guess1 (mapcar '+ cenA (mapcar '* uA (list rA ra rA)))
	  uB (uvec cenB guess1)
    )
    (setq guess2
	   (mapcar '+ cenB (mapcar '* uB (list rB rB rB)))
    )
    (setq i (+ i 1))
    (setq d (distance guess1 guess2))
  )					; end while
  (if (> i 20)
    (setq ans nil)
    (setq ans guess2)
  )
)

 

lee.minardi
0 Likes
Message 9 of 10

hak_vz
Advisor
Advisor

This is really interesting packaging problem that is combination of Problem of Appolonius , Soddy's Circles

and Descartes circle theorem.

 

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 10 of 10

arpansark0544TCX
Advocate
Advocate
Thank you for your wonderful insight.
0 Likes