如何在Java中将交叉部分的大小放在圆圈中

Lol*_*ewn 6 java math floating-point geometry

我需要这个图像的黑色部分的大小:
图片

我已经做了一些关于如何在普通数学中找到它的研究,我被指向这个网站:网站

得到它的最终答案是 图片http://mathworld.wolfram.com/images/equations/Circle-CircleIntersection/Inline41.gif

其中r是第一个圆的半径,R是第二个圆的半径,d是两个中心之间的距离.

我试图用来获取此大小的代码如下:

float r = getRadius1();
float R = e.getRadius1();
float deltaX = Math.abs((getX()  + getRadius()) - (e.getX() + e.getRadius()));
float deltaY =  Math.abs((getY()  + getRadius()) - (e.getY() + e.getRadius()));
float d = (float) Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));

float part, part2, part3;
//Chopping it in parts, because it's easier.

part = (float) (Math.pow(r,2) * Math.acos(
      Math.toRadians((Math.pow(d, 2) + Math.pow(r, 2) - Math.pow(R, 2))/(2*d*r))));

part2 = (float) (Math.pow(R,2) * Math.acos(
      Math.toRadians((Math.pow(d, 2) + Math.pow(R, 2) - Math.pow(r, 2))/(2*d*R))));

part3 = (float) (0.5 * Math.sqrt((-d + r + R) * (d+r-R) * (d-r+R) * (d+r+R)));

float res = part + part2 - part3; 

Main.log(res + "       " + part + " " + part2 + " " + part3+ "       "
         + r + " " + R  + " " + d);
//logs the data and System.out's it
Run Code Online (Sandbox Code Playgroud)

我做了一些测试,输出是这样的:

1345.9663       621.6233 971.1231 246.78008       20.0 25.0 43.528286
Run Code Online (Sandbox Code Playgroud)

这表明重叠部分的大小大于圆形本身(即r^2 * PI).

我做错了什么?

Tho*_*mas 5

只是一个猜测(如我的评论中所述):尝试删除Math.toRadians(...)转换.

由于公式中没有涉及度,而是半径,我假设cos -1(...)的参数已经是弧度值.

如果我删除转换并运行您的代码,我会得到以下重叠区域大小:11.163887023925781 这似乎是合理的,因为两个中心之间的线上的重叠段的长度是20 + 25 - 43.5 = 1.5(近似的)

编辑:

如果我将距离设置为5(较小的圆圈完全包含在较大的圆圈中但接触其边缘),我得到的重叠区域大小1256.63恰好是较小圆圈的面积(20 2*Π).如果距离小于半径的差值(即在小于5的情况下),计算似乎不起作用,但这可能只是数值表示的问题(正常数据类型可能无法表示某些中间结果).