# Circle intersection with known intersect area and circle radii

I’m trying to have grasshopper define and/or output the distance between two circles with known radii and known intersect area. I am thinking this is a python script but it is beyond my gh skills. Any help would be greatly appreciated. Thanks.

If you know the radii of both circles, how come you don’t know their center points?

In general, there are two solution circles: from the center point of the smaller circle with radius d and from the center point of the larger circle with radius d. So if one of the circle centers is known, the other circle center has infinite solutions.

You may be able to enter your formula for the area of intersection into a symbolic solver like Maxima and solve for the distance d.

Circle intersection area.gh (11.3 KB)

Maybe there is no one answer. Nevertheless you can use optimization solver to get the closest answers.
Here for instance the R = 20 and r = 10.604 and the intersection area is 5. then the d is close to 29.5

I think that you still need one parameter, that is the length of the arch of one circle that lies within the other circle, or, alternatively, the angle subtended by that arc. You can then reverse the procedure of finding an area as nicely detailed in the following blog
https://www.xarg.org/2016/07/calculate-the-intersection-area-of-two-circles/

Thanks Breccia (and all) for the thoughts. From what I can understand from the area of intersection equations, all you need is the radius of both circles and the distance between center points to determine the intersection area. This made me think it was possible to work backwards (if I know the intersection area) to get the distance between center points.

Below is a screen shot of the two definitions - the top is using region intersection to get the area. The bottom script I am thinking I could use an SDL line with an equation giving me the “L” based on the three variables. Attached is the gh file.

thanks again.

circle area intersect.gh (13.6 KB)

A high ‘Count’ (precision) value in this model incurs a heavy performance penalty when changing R1 or R2, hence the Data Dam in the red group. But the ‘area’ slider (blue group) responds quickly.

circle_intersection_2020May19b.gh (19.1 KB)

It’s very contrived, of course, because we know the distance between the circle centroids without doing any calculations.

1 Like

``````private void RunScript(double area1, double area2, double xArea, double tol, ref object A)
{
if(tol <= 0)
{
Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Tolerance must be > 0");
return;
}
var r1 = Math.Abs(Math.Sqrt(area1 / Math.PI));
var r2 = Math.Abs(Math.Sqrt(area2 / Math.PI));
var r = r1;
var R = r2;
if(R < r)
{
r = r2;
R = r1;
}
if(Math.Min(area1, area2) - xArea <= 0)
{
Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "One circle lying inside another");
A = String.Format("<{0}", R - r);
return;
}
if(xArea <= 0)
{
Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Two circles lying outside each other");
A = String.Format(">{0}", R + r);
return;
}
var d = R;
for(var i = 0; i < 1 / tol * 2; i++)
{
double area = GetIntersectionArea(r, R, d);
if (Math.Abs(area - xArea) < tol)
break;
else
d += (area - xArea) * tol;
}
A = d;
}
public double GetIntersectionArea(double r, double R, double d)
{
var part1 = r * r * Math.Acos((d * d + r * r - R * R) / (2 * d * r));
var part2 = R * R * Math.Acos((d * d + R * R - r * r) / (2 * d * R));
var part3 = 0.5 * Math.Sqrt((-d + r + R) * (d + r - R) * (d - r + R) * (d + r + R));
return part1 + part2 - part3;
}