Given two circles:
x1, y1) with radius1
x2, y2) with radius2
How do you calculate the area of their intersection? All standard math functions (sin, cos, etc.) are available, of course.
The intersections of two circles determine a line known as the radical line.
If d≥r1+r2, the circles intersect at most up to a point (when d=r1+r2) and therefore the intersection area is zero. On the other extreme, if d+r2≤r1, circle C2 is entirely contained within C1 and the intersection area is the area of C2 itself: πr22.
Okay, using the Wolfram link and Misnomer's cue to look at equation 14, I have derived the following Java solution using the variables I listed and the distance between the centers (which can trivially be derived from them):
Double r = radius1;
Double R = radius2;
Double d = distance;
if(R < r){
// swap
r = radius2;
R = radius1;
}
Double part1 = r*r*Math.acos((d*d + r*r - R*R)/(2*d*r));
Double part2 = R*R*Math.acos((d*d + R*R - r*r)/(2*d*R));
Double part3 = 0.5*Math.sqrt((-d+r+R)*(d+r-R)*(d-r+R)*(d+r+R));
Double intersectionArea = part1 + part2 - part3;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With