java - Complex Polygon Area -
clonelist = point[] (series of points put constructor) have tried many different times fix formula, coming wanting. formula found on http://en.wikipedia.org/wiki/shoelace_formula index(i) point has both x , y values.
public double getarea() { double area = 0; (int = 0; < 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); }
i'm not familiar formula ill give shot... me looks though not following formula correctly, implementation(based on gleaned wiki page xd)
public double getarea(){ double area = 0; int n = clonelist.length; double firstsum = 0; double secondsum = 0; for(int = 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; }
Comments
Post a Comment