online advertising

Sunday, May 1, 2016

Moon area problem

Problem:

Solution:

I am an engineer, therefore I am thinking about solving this using integration. But the area defined is hard to compute using integration because the curves defining it are not functions. (For example, at the far right end, the circle has both its upper point and lower point), so I figured something else.


 The yellow area is what we wanted, note that it is super easy to calculate the red area, as well as the sum of all colored areas, which leave us the question, how to we compute the green area? Because if we can compute the green area, the problem is pretty much solved.

The red area is simply the difference between a square of side 0.5 and a quarter circle with radius 0.5), so it is $ 0.5^2 - \frac{\pi 0.5^2}{4} \approx 0.053650459 $

The sum of all colored area is simply the same shape with side doubled, so the area is four times the red area and it is approximately $ 0.053650459 \times 4 \approx 0.214601837 $

Next we focus on the green area, zooming in, we see that is a sum of two areas, the dark green and the light green one, it is now obvious that the left one can be solved by integration, it is not so obvious that the right one can be computed relatively easily with the left hand side result as we shall see.



You probably see in the diagram that the x coordinate of the intersection point is approximately 0.29, why is that?

Let's solve this:

The equation of the big circle is $ x^2 + (y - 1)^2 = 1 \implies x^2 + y^2 - 2y = 0 $.
The equation of the small circle is $ (x - 0.5)^2 + (y - 0.5)^2 = (0.5)^2 \implies x^2 + y^2 - x - y + 0.25 = 0 $

Subtracting these two equations give $ x - y - 0.25 = 0 \implies y = x - 0.25 $.

Putting this back into the first equation gives $ x^2 + (x - 0.25 - 1)^2 = 1 $, solving we get $ x = 2x^2 - 2.5x + 0.5625 = 0 $ and therefore $ x = \frac{2.5 \pm \sqrt{1.75}}{4} $, we take the smaller value $ \frac{2.5 - \sqrt{1.75}}{4} $ as this is the leftmost intersection point.

Next, we compute we find an explicit formula for the lower big circle. We already have the implicit form: $ x^2 + (y - 1)^2 = 1 $, making $ y $ the subject gives $ y = 1 \pm \sqrt{1 - x^2} $, as this is the lower half of the circle so we take the negative sign $ y = 1 - \sqrt{1 - x^2} $

Now we do the integration, the form is simply asking for trigonometric subsitution, so we are doing it.

Let $ x = \sin u $, $ dx = \cos u du $

$ \int{1 - \sqrt{1 - x^2}dx} $
$ \int{(1 - \sqrt{1 - \sin^2 u})\cos u du} $
$ \int{(1 - \sqrt{\cos^2 u})\cos u du} $
$ \int{(1 - \cos u)\cos u du} $
$ \int{(\cos u - \cos^2 u) du} $
$ \int{(\cos u - \frac{1 + \cos 2u}{2}) du} $
$ \sin u - \frac{1}{2}(u + \frac{1}{2}\sin 2u) $
$ \sin u - \frac{1}{2}(u + \sin u \cos u) + C $
$ x - \frac{1}{2}(\arcsin x + x \sqrt{1 - x^2}) + C $

This formula gives us the dark green area (note that we can just set $ C = 0 $ as the formula gives 0 when $ x = 0 $)

If we substitute the number, the dark green area is approximately $ 0.004304482 $

If we observe carefully, the light green area is actually a similar figure. If we double the image so that the small circle has radius 1, the shape of the area is exactly the same, so we can use exactly the same formula there.

The base has length $ 2 \times (0.5 - 0.29) $ long in the doubled area, we plug in the formula, and then scale it back down (so that area is divided by 4), we get the value $ 0.002980577 $

Last but not least, given all the areas, we can now compute the moon area to be $ 0.14638126 $.

Using this simple C# Monte Carlos simulation program, I verified the answer above should be correct.

namespace Moon
{
    using System;

    class Program
    {
        static void Main(string[] args)
        {
            Random random = new Random(0);
            int numTrials = 10000000;
            int hitTrials = 0;
            for (int i = 0; i < numTrials; i++)
            {
                double x = random.NextDouble();
                double y = random.NextDouble();
                bool outsideQuarter = (x * x + y * y) > 1;
                bool insideCircle = (x - 0.5) * (x - 0.5) + (y - 0.5) * (y - 0.5) < 0.25;
                bool insideMoon = outsideQuarter && insideCircle;
                if (insideMoon)
                {
                    hitTrials++;
                }
            }
            Console.WriteLine((hitTrials + 0.0) / numTrials);
        }
    }
}

One last problem remain though, is there a simpler solution?