Java 复杂多边形区域
克隆列表=点[](放入构造函数的一系列点) 我已经尝试了很多次来修正这个公式,但我还是想要。这个公式是在 索引(i)是同时具有x和y值的点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
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;
}