Largest radius for 4 circles in variable rectangle

SnakeShake

New member
Joined
May 14, 2015
Messages
3
Hello,

first post and I hope I'm in the right section.

My problem is as follows, I have a variable rectangle (a smartphone screen to be precise) and I need to fit 4 circular buttons in it. I'd like them to have the largest radius possible without having them overlap.

So my givens are : rectangle width, rectangle height and the number of circles (4) (and that the circles will be the same size).

I can ignore any rectangles where (width > height) and (height > width * 4).

My two extremes thus are two aligned rows of 2 and one column of 4.

I've figured out that if I can get the angle of an imaginary line going through the centres of the top two circles I can Sine that number to get the percentage of width of the second circle that goes "below" the first circle and using that percentage along with the width of the rectangle I can determine the radius but I haven't figured out a way of getting that angle.

I really hope I've explained my problem in a clear way and that someone can help...

Thanks in advance anyone!

EDIT FOR SOLUTION:
Well, after some puzzling and getting other minds to work alongside me (with the other minds doing most of the work I'll admit) it boiled down to this:

W = 2r + 2r sin (alpha)
H = 2r + 6r cos (alpha)

Which was then finalised as:

r = (9*W+H)/2 - (3/2) * square-root-of(8*W2+2*W*H)

So there you have it, thanks for all the replies!
 
Last edited:
Hello,

first post and I hope I'm in the right section.

My problem is as follows, I have a variable rectangle (a smartphone screen to be precise) and I need to fit 4 circular buttons in it. I'd like them to have the largest radius possible without having them overlap.

So my givens are : rectangle width, rectangle height and the number of circles (4) (and that the circles will be the same size).

I can ignore any rectangles where (width > height) and (height > width * 4).

My two extremes thus are two aligned rows of 2 and one column of 4.

I've figured out that if I can get the angle of an imaginary line going through the centres of the top two circles I can Sine that number to get the percentage of width of the second circle that goes "below" the first circle and using that percentage along with the width of the rectangle I can determine the radius but I haven't figured out a way of getting that angle.

I really hope I've explained my problem in a clear way and that someone can help...

Thanks in advance anyone!
This is just a packing problem; circles or cylinders in a rectangle. If you search on that you should get some good hits. Although I haven't looked at it closely one that might be of interest is
http://urbanlabglobalcities.blogspot.com/2010_03_01_archive.html

You also look through
https://www.google.com/search?q=pac...orld.wolfram.com%2FCirclePacking.html;477;200

It looks like your approach is a good one. In the unbounded plane this might be the hex packing but I'm not sure.
 
Last edited:
Typing out loud...

so, with h = height and w = width and w =>h, then:

if rectangle is a square (h = w), diameter = h/2

if w => 4h, diameter = h

for all other cases, special calculation/packing required

Correct, or do I need another coffee ?
Certainly if w=4h, h is an upper bound for the diameter and, since you can make 4 circles with h as a diameter, is it the least upper bound. I would think same sort of argument for square.

However, that is the boundaries. Still not sure about intermediate.
 
Thanks for the replies!

@Denis:
Seems right though I'm used to using <= instead of =>
programming style :)
So H will be equal or greater than W

and

H will be equal or less than W * 4


@Ishuda:
The first link is more about squares, though the second one has some useful bits towards the end...There's one drawing that gave me a new perspective (by simply flipping the problem 90 degrees) and I'll see if I can get somewhere with that...If I find the solution I'll mention it here for the next generations who'll have this incredibly specific problem...
 
Quite a headachy problem!
Played around a bit with it
(including using 4 saucers on a dish drying towel!)

This works (but not 100% sure if it covers all cases):

r = max radius
h = rectangle height
w = rectangle width

r = [w + 2(h - SQRT(hw)] / 4
where:
w => h and w =< 4h

Example: a 15by25 rectangle means max radius of 4.0675...

Try a few and come back if you find something you didn't expect.

Works at the end points
 
What does that mean?

For w=h and w=4h.

Looking around, I wonder whether one might tackle this as packing hexagons into the rectangle (and use the in-circle for the circles) and, if so, whether it might be easier?
 
Well then allow me to jump in and shout NO at myself!

Turns out that equation only works if W/H >= 1.34, so visually speaking when circle 1 and 3 (and subsequently 2 and 4) start separating to accommodate the other circles...

For W/H < 1.34:
r = (w+2h - sqrt(4wh - 3w^2) )/8

Hope this is of some use to anyone...ever...
 
Top