有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java查找两个相同圆的重叠级别百分比

我必须画两个圆心为x1,y1和x2,y2的圆(圆1,圆2),大小相同

现在我想计算cir2和cir1叠加的百分比(百分比) (ex)如果cir2完全覆盖cir1,然后叠加=100% 如果完成一半叠加,分数将为50%,如果根本不叠加,分数将为0%

如何做到这一点

任何指南


共 (1) 个答案

  1. # 1 楼答案

    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....!