To write a subroutine to calculate the common area we have first to recognize the relationship between the circles, for this purpose we can use the following table.
| r1 - r2 | > D