Contrary to the joke, it is possible to fit a square peg into a round hole (and a round peg into a square hole). In fact, they fit with mathematical elegance.

This problem is relevant when building software GUIs such as web pages. I had a circular button to make (*the green circle*). That circle occupied a square block of real-estate on the screen (*the orange square*). It needed a square image to fit inside it (*the blue square*). The question: how big could the image be, and still fit?

In terms of the diagram above, how big can the blue square be, while fitting inside the green circle?

Turn your head sideways, and the solution reveals itself.

Rotating the picture shows that **the diameter of the circle is the same as the diagonal length across the blue square**. (This is also the same as the length of each side of the orange square.)

Call the blue square’s diagonal length ** d**, and its side length

**. Then, by the Pythagorean Theorem,**

*s*When a square is inscribed within a circle, the side length of the square is equal to the diameter of the circle, divided by the square root of 2.

## Leave a Reply