Minimal Symmetric Difference of Concentric Disk and Square

Logos, icons, avatars and similar graphics are often displayed in disk or square shaped frames. To design graphics that work well with both frame shapes, I wanted to know the relative size of a disk and a square with common center and minimal symmetric difference.

More formally, given the unit disk D1 O, centered on the origin O, and a square S aO, with side length a and centered on the origin, determine amin, such that the symmetric difference of disk and square is minimal; as a formula: amin = mina D1O SaO .


Figure 1 shows two cases for a=2 and a=2.

Figure 1:  a=2  and a=2

If a is less than 2 (the square is a proper subset of the disk), the symmetric difference of disk and square is larger than for a=2.

Similary, if a is greater than 2 (that means the disk is a proper subset of the square), the symmetric difference of disk and square is larger than for a=2.

So, overall 2 amin 2 .

Parts of Set Difference

If 2 < amin < 2 , as exemplified in figure 2, then the symmetric difference consists of four corners of the square and four segments of the disk. So, we need to determine the area of a corner, Aa, and area of a segment, Aa, as functions of a and minimize their sum.

Figure 2:  Symmetric difference of disk and square shown in black for a=45  

We will almost do that. Instead of functions of a, we will determine the areas as functions of an angle with a one-to-one relationship to a for the values we are interested in, minimize their sum, and then convert back to a.


Figure 3 illustrates the case of the segment. We call the half angle of the segment α. Since the radius of our disk is 1,


holds. We will determine the area of the segment (and later that of the corner) as functions of the angle α.

a/2 α
Figure 3:  A graphic that helps with the derivation of the area of the segments, Aa, in the symmetric difference

Again using the fact that the radius of our disk is 1, we get the following simple formula for the area of the segement (see for example the Wikipedia article on circular segments):

Aα = α - 1 2 sin 2 α .


Next we determine the area of the corner. The case is illustrated in figure 4. What we called a corner so far, is formally a isosceles right triangle minus a segment. So the area of a corner, Aα, is the area of a triangle, Bα, minus the area of a segment, Bα, or

Aα = Bα - Bα .
α β a/2 b
Figure 4:  A graphic that helps with the derivation of the area of the corners, Aα, in the symmetric difference

We call the half angle of the segment β and half of the segement's corresponding secant b.

Then, the area of the triangle is b2, which is sin2β.

Next, we apply three equalities to transform the formula further. First, applying sin2x = 12 1 - cos2x gives us 12 1 - cos2β . Then, we use β=π4-α to get 12 1 - cos π2 - 2α . Finally, cos π2-x = sinx gives us

Bα = 12 - 12 sin2α .

Now, for the segment we can use the same area formula as we did for Aα, since it is a segment of our unit disk, which has radius 1. Thus the area of the segment is β - 1 2 sin 2 β . We apply two transformations. First, we us β=π4-α to get - α - 1 2 sin π 2 - 2 α + π 4 . And second, we apply the equation sin π2-x = cosx to get

Bα = - α - 1 2 cos 2 α + π 4 .

So overall, the we have the following formula area of a corner as a function of α:

Aα = Bα - Bα = α -12 sin2α +12 cos2α -π4 +12 .

Optimization Problem

In the previous sections, we determined the area of one corner and one segment. The symmetric difference consists of four corners and four segments, hence the area of the symmetric difference as a function of α is given by

Aα = 4 Aα + Aα = 8α - 4sin2α + 2cos2α - π + 2 .

Before we find the minimum, we have a look at the domain of Aα. We already determined, that the minimum must be assumed for a between 2 and 2. We also know that α = acosa2 , a bijection for the values of a that we are interested in. So Aα should assume the minimum for α between 0 and π4.

Now, to find the minimum, we write down the derivative of Aα:

A'α = 8 - 8cos2α - 4sin2α .

From this we get the following equation for the derivative's roots:

2 = 2cos2α + sin2α .

We apply two equalities to transform that equation. First we use cos2x = 1 - sin2x , which gives us 0 = - 2sin2α + sin2α . Second we use sin2x = 2sinx cosx , which gives us 0 = - 2sin2α + 2 sinα cosα . Finally, we factor out sinα and multiply by -1:

0 = sinα 2 sinα - cosα .

sinα is only 0 for α=0 in A's domain, which we will have to look at anyway, as it is the lower bound of the domain.

Now, 2sinα - cosα = 0 if and only if 2=cotα if and only if α = atan12 .

Applying A to atan12 and the lower and upper bound of the domain shows that A is minimal at atan12 .

Converting back to a yields amin = 2cos atan12 = 45 , where the latter equality holds according to some arcane trigonometry.


Figure 5 shows the square's and disk's intersection with optimal a.

Figure 5:  Intersection of square and disk with a=45 , the optimum.  

Some Remarks

Now that I know the solution to the mathematical problem, the question is: does it solve my initial problem. Let us assume we have a graphic designed to fit the shape shown in figure 5. Then it will work well in every system that uses only one shape (circle or square) as a frame for the graphic in every context. However, if a system uses graphics with circle or square shaped frames depending on context, the scaling might not fit well. However, that is a problem you have with every graphic. So, I guess it does helps with the problem.

I also looked a bit on an extension of this problem, with not only a fixed disk and variable size square, but also a variable size hexagon. That makes the problem a lot more complicated, which made me stop working on it.