我有一个关于编写java程序的问题,并且在程序的一部分中检查圆圈是否在任何点重叠或交叉,并显示它们是否存在。
我相信这样做的公式是 (r1 + r2)^ 2< =(x2-x1)^ 2 +(y2-y1)^ 2
将此公式应用于我的代码后,无法检测是否重叠或相交。
//variables
//crOneRadius = radius of circle 1
//crTwoRadius = radius of circle 2
//crOneCenterX = x axis location of circle 1
//crOneCenterX = y axis location of circle 1
//crTwoCenterX = x axis location of circle 2
//crTwoCenterX = y axis location of circle 2
//BOoverlap = is boolean if it is ovelapping circles set to true
if((crOneRadius+crTwoRadius)*(crOneRadius+crTwoRadius)<=((crTwoCenterX-crOneCenterX)*(crTwoCenterX-crOneCenterX))+((crTwoCenterY-crOneCenterY)*(crTwoCenterY-crOneCenterY)))
BOoverlap=true;//overlap is true