Program The rantings of a lunatic Scientist

Overlapping Circles

C/C++ Daily Programmer

This program expects 4 arguments to be passed in on the command line representing the location (as xy coords) of two circles. The program then computes the total area covered by the two circles including any possible overlap between them and prints the area to the console.

Despite the fact that this problem can be solved numerically in constant time using the equation:

D = sqrt( (x-u)^2 + (y-v)^2 )
A = (2 * PI) - (2 * ACos( D / 2 )) + (D / 2) * sqrt( 4 - D^2 )

I thought it would be more of a programming challenge to write a simple monte carlo simulation to solve for the area. The simulation can easily be modified to allow an arbitrary number of circles to be inputed at varying radii.

Input (on the command line)

x y u v


-0.5 0 0.5 0