Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java找到两个可能重叠矩形的面积之和?_Java - Fatal编程技术网

如何使用Java找到两个可能重叠矩形的面积之和?

如何使用Java找到两个可能重叠矩形的面积之和?,java,Java,我需要使用Java找到两个可能重叠矩形的面积之和 条件: 每个矩形由如下4个双倍体组成:(x0,y0,x1,y1) 它们可能在边缘接触、重叠或没有任何接触 非常感谢您的帮助。在我下面的代码中,有许多案例需要处理,我仅针对此图中的案例展示了这些代码: 下面是该案例的代码,您需要为其他案例编写: public class Problem { public static class Rectangle { double x0; double y0; double x1;

我需要使用Java找到两个可能重叠矩形的面积之和

条件: 每个矩形由如下4个双倍体组成:(x0,y0,x1,y1) 它们可能在边缘接触、重叠或没有任何接触


非常感谢您的帮助。

在我下面的代码中,有许多案例需要处理,我仅针对此图中的案例展示了这些代码:

下面是该案例的代码,您需要为其他案例编写:

public class Problem {

public static class Rectangle {

    double x0;
    double y0;
    double x1;
    double y1;

    Rectangle(double x0, double y0, double x1, double y1) {

        this.x0 = x0;
        this.y0 = y0;
        this.x1 = x1;
        this.y1 = y1;

    }

}

public static void main(String[] args) {

    Rectangle A = new Rectangle(2.0, 2.0, 10.0, 5.0);
    Rectangle B = new Rectangle(0.0, 0.0, 6.5, 3.5);
    double area = 0.0;


    if(A.x1 - B.x0 > 0 && A.y1 - B.y1 > 0) {

        System.out.println("they're overlaping");
        area = (A.x1 - B.x0) * (A.y1 - B.y1);
        System.out.println(area);

    } else if  (B.x1 - A.x0 > 0 && B.y1 - A.y1 > 0) {

        System.out.println("they're overlaping");
        area = (B.x1 - A.x0) * (B.y1 - A.y1);
        System.out.println(area);

    } else if (other conditions....) {

        // you're code here
    }


}

}

第一个if条件与上图所示完全相同,第二个if条件是B和A切换位置时(B在左上方,A在右下方)。

请详细说明您的要求好吗?什么是
x0、y0、x1、y1
?到目前为止你都试了些什么?