找到两个相同圆圈的百分比叠加级别

时间:2016-04-08 08:21:48

标签: java

我必须有两个圆圈(圆圈-1,圆圈-2),其中心为x1,y1和x2,y2随后具有相同的尺寸。

现在我要计算cir1在cir1上的叠加百分比(百分比) (ex)如果cir2完全覆盖cir1然后叠加= 100% 如果完成一半叠加,则得分将为50%,如果不叠加则= 0%。

怎么做.....?

任何指南......

1 个答案:

答案 0 :(得分:0)

Thanks Andy. 
I got an idea from the link you provide. 
Though the idea is not the best, but it solves the purpose..

double radius = 40.0;
int x1 =100;    //first Circle X value
int y1 = 100;   //first Circle Y value
int x2 = 100;   //second Circle X value
int y2 = 100;  //second Circle Y value

double iDist = Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
double per = (100.0-(iDist/radius)*100);    //get the value in %
System.out.println("Distance: "+iDist + "("+per+"%)");


OUTPUT:

if values are (100,100) and (100,100) then o/p : 100%
if values are (100,100) and (120,100) then o/p : 50%
if values are (100,100) and (140,100) then o/p : 0%
if values are (100,100) and (600,600) then o/p : percentage in negative value (ex) - 973%


All the best....!