user348173 user348173 - 1 year ago 126
Javascript Question

Align rectangles inside circle

I have a circle and I need to fill this circle by rectangles. Something like this:
enter image description here

Is there some algorithm for this or advice where to start?
I use fabric.js for drawing. This is playground. But, the question is more about math probably. I think there should be some formula, I hope.

Answer Source

I'll go with "close enough" for now: subtract the rectangle length from the radius, then multiply the result by 2π. That's the inner circumference. Now divide that by the rectangle width (and round down) to get the number of rectangles. Divide 360° by that to get the angles at which to draw them.

Here's a demo:,output

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download