Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 930219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:17:58+00:00 2026-05-15T20:17:58+00:00

Given n squares with edge length l , how can I determine the minimum

  • 0

Given n squares with edge length l, how can I determine the minimum radius r of the circle so that I can distribute all squares evenly along the perimeter of the circle without them overlapping? (Constraint: the first square will always be positioned at 12 o’clock.)

Followup question: how can I place n identical rectangles with height h and width w?

example
(source: n3rd.org)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:17:58+00:00Added an answer on May 15, 2026 at 8:17 pm

    There may be a mathematically clever way to do this, but I wouldn’t know.
    I think it’s complicated a bit by the fact that the geometry is different for every different number of squares; for 4 it’s a rhombus, for 5 it’s a pentagon and so on.

    What I’d do is place those squares on a 1 unit circle (much too small, I know, bear with me) distributed equally on it. That’s easy enough, just subtend (divide) your 360 degrees by the number of squares. Then just test all your squares for overlap against their neighbors; if they overlap, increase the radius.

    You can make this procedure less stupid than it sounds by using an intelligent algorithm to approach the right size. I’m thinking of something like Newton’s algorithm: Given two successive guesses, of which one is too small and one is too big, your next guess needs to be the average of those two.

    You can iterate down to any precision you like. Stop whenever the distance between guesses is smaller than some arbitrary small margin of error.

    EDIT I have a better solution:

    I was thinking about what to tell you if you asked “how will I know if squares overlap?” This gave me an idea on how to calculate the circle size exactly, in one step:

    Place your squares on a much-too-small circle. You know how: Calculate the points on the circle where your 360/n angles intersect it, and put the center of the square there. Actually, you don’t need to place squares yet, the next steps only require midpoints.

    To calculate the minimum distance of a square to its neighbor: Calculate the difference in X and the difference in Y of the midpoints, and take the minimum of those. The X’s and Y’s are actually just cosines and sines on the circle.

    You’ll want the minimum of any square against its neighbor (clockwise, say). So you need to work your way around the circle to find the very smallest one.

    The minimum (X or Y) distance between the squares needs to become 1.0 . So just take the reciprocal of the minimum distance and multiply the circle’s size by that. Presto, your circle is the right size.

    EDIT

    Without losing generality, I think it’s possible to nail my solution down a bit so it’s close to coding. Here’s a refinement:

    • Assume the squares have size 1, i.e. each side has a length of 1 unit. In the end, your boxes will surely be larger than 1 pixel but it’s just a matter of scaling.
    • Get rid of the corner cases:

      if (n < 2) throw new IllegalArgumentException();
      if (n == 2) return 0.5; // 2 squares will fit exactly on a circle of radius 0.5
      
    • Start with a circle size r of 0.5, which will surely be too small for any number of squares > 2.

      r = 0.5;
      dmin = 1.0; // start assuming minimum distance is fine
      a = 2 * PI / n;
      for (p1 = 0.0; p1 <= PI; p1+=a) { // starting with angle 0, try all points till halfway around
         // (yeah, we're starting east, not north. doesn't matter)
         p2 = p1 + a; // next point on the circle 
         dx = abs(r * cos(p2) - r * cos(p1))
         dy = abs(r * sin(p2) - r * sin(p1))
         dmin = min(dmin, dx, dy)
      }
      
      r = r / dmin;
      

    EDIT

    I turned this into real Java code and got something quite similar to this to run. Code and results here: http://ideone.com/r9aiu

    I created graphical output using GnuPlot. I was able to create simple diagrams of boxes arranged in a circle by cut-and-pasting the point sets from the output into a data file and then running

    plot '5.dat' with boxxyerrorbars
    

    The .5‘s in the file serve to size the boxes… lazy but working solution. The .5 is applied to both sides of the center, so the boxes end up being exactly 1.0 in size.

    Alas, my algorithm doesn’t work. It makes the radii far too large, thus placing the boxes much further apart than necessary. Even scaling down by a factor of 2 (could have been a mistake to use 0.5 in some places) didn’t help.

    Sorry, I give up. Maybe my approach can be salvaged, but it doesn’t work the way I had though it would. 🙁


    EDIT

    I hate giving up. I was about to leave my PC when I thought of a way to salvage my algorithm:

    The algorithm was adjusting the smaller of the X or Y distances to be at least 1. It’s easy to demonstrate that’s just plain silly. When you have a lot of boxes then at the eastern and western edges of the circle you have boxes stacked almost directly on top of each other, with their X’s very close to one another but they are saved from touching by having just enough Y distance between them.

    So… to make this work, you must scale the maximum of dx and dy to be (for all cases) at least the radius (or was it double the radius?).

    Corrected code is here: http://ideone.com/EQ03g http://ideone.com/VRyyo

    Tested again in GnuPlot, it produces beautiful little circles of boxes where sometimes just 1 or 2 boxes are exactly touching. Problem solved! 🙂


    (These images are wider than they are tall because GnuPlot didn’t know I wanted proportional layout. Just imagine the whole works squeezed into a square shape 🙂 )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that the web application doesn't have su privileges, I'd like to execute a
Given a canvas, let's say 10x10, and given 3 rectangles/squares. Canvas = 10x10 Rectangle
I have a table that is 26 squares by 26 squares. Each square is
Given inputs 1-32 how can I generate the below output? in. out 1 1
Given a grid of nxn squares, where each square has an id, the first(top
Given a rectangle with width and height, fill it with n squares (n is
Given a cubic polynomial estimated using least-squares regression, I am interested in a simple
Given a square image, how can you get the iPhone icon effect using ImageMagick's
When given a square matrix, what would be the best way to find all
Given an integer area A, how can one find integer sides w and h

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.