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 , centered on the origin , and a square , with side length and centered on the origin, determine , such that the symmetric difference of disk and square is minimal; as a formula: .
Figure 1 shows two cases for and .
If is less than (the square is a proper subset of the disk), the symmetric difference of disk and square is larger than for .
Similary, if is greater than (that means the disk is a proper subset of the square), the symmetric difference of disk and square is larger than for .
So, overall .
Parts of Set Difference
If , 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, , and area of a segment, , as functions of and minimize their sum.
We will almost do that. Instead of functions of , we will determine the areas as functions of an angle with a one-to-one relationship to for the values we are interested in, minimize their sum, and then convert back to .
Figure 3 illustrates the case of the segment. We call the half angle of the segment . Since the radius of our disk is ,
holds. We will determine the area of the segment (and later that of the corner) as functions of the angle .
Again using the fact that the radius of our disk is , we get the following simple formula for the area of the segement (see for example the Wikipedia article on circular segments):.
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, , is the area of a triangle, , minus the area of a segment, , or.
We call the half angle of the segment and half of the segement's corresponding secant .
Then, the area of the triangle is , which is .
Next, we apply three equalities to transform the formula further. First, applying gives us . Then, we use to get . Finally, gives us.
Now, for the segment we can use the same area formula as we did for , since it is a segment of our unit disk, which has radius . Thus the area of the segment is . We apply two transformations. First, we us to get . And second, we apply the equation to get.
So overall, the we have the following formula area of a corner as a function of :.
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.
Before we find the minimum, we have a look at the domain of . We already determined, that the minimum must be assumed for between and . We also know that , a bijection for the values of that we are interested in. So should assume the minimum for between and .
Now, to find the minimum, we write down the derivative of :.
From this we get the following equation for the derivative's roots:.
We apply two equalities to transform that equation. First we use , which gives us . Second we use , which gives us . Finally, we factor out and multiply by :.
is only for in 's domain, which we will have to look at anyway, as it is the lower bound of the domain.
Now, if and only if if and only if .
Applying to and the lower and upper bound of the domain shows that is minimal at .
Converting back to yields , where the latter equality holds according to some arcane trigonometry.
Figure 5 shows the square's and disk's intersection with optimal .
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.