Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.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_Arrays_Area - Fatal编程技术网

Java 复杂多边形区域

Java 复杂多边形区域,java,arrays,area,Java,Arrays,Area,克隆列表=点[](放入构造函数的一系列点) 我已经尝试了很多次来修正这个公式,但我还是想要。这个公式是在 索引(i)是同时具有x和y值的点 public double getArea() { double area = 0; for (int i = 0; i < cloneList.length-1; i++){ area += cloneList[i].getX()*cloneList[i+1].getY() - cloneList[i+1].getX

克隆列表=点[](放入构造函数的一系列点) 我已经尝试了很多次来修正这个公式,但我还是想要。这个公式是在 索引(i)是同时具有x和y值的点

public double getArea() {
    double area = 0;


    for (int i = 0; i < cloneList.length-1; i++){



    area += cloneList[i].getX()*cloneList[i+1].getY() - cloneList[i+1].getX()+cloneList[i].getY();

}


    area = area/2;
    //System.out.println(Math.abs(area));
return Math.abs(area);
}
public-double-getArea(){
双面积=0;
for(int i=0;i
我不熟悉这个公式,但我会试一试。。。 在我看来,您似乎没有正确地遵循公式,这将是我的实现(基于我从wiki页面xD收集的信息)

public-double-getArea(){
双面积=0;
int n=克隆列表.length;
双首和=0;
双二次和=0;
for(int i=0;i
当i=cloneList.length-1时,您会向变量区域添加什么?提示:在这一点上添加不是正确的。嗯。。。我不知道。。
public double getArea(){
    double area = 0;
    int n = cloneList.length;
    double firstSum = 0;
    double secondSum = 0;
    for(int i = 0;i< cloneList.length - 1;i++){
        firstSum+= cloneList[i].getX()*cloneList[i+1].getY();
        secondSum+= cloneList[i+1].getX()*cloneList[i].getY();
    }
    firstSum+=cloneList[cloneList.length-1].getX()*cloneList[0].getY();
    secondSum-=cloneList[0].getX()*cloneList[cloneList.length-1].getY();

    double finalSum = firstSum-secondSum;
    area = Math.abs(finalSum)/2;
    return area;



}