double area(){//top为总点数,即0~top-1,res为点数组 double sum; sum = res[0].y * (res[top-1].x-res[1].x); for(int i = 1; i < top; i ++) sum += p[res[i]].y * (res[i-1].x-res[(i+1)%top].x); return sum / 2; }
时间: 2024-10-24 10:34:39
double area(){//top为总点数,即0~top-1,res为点数组 double sum; sum = res[0].y * (res[top-1].x-res[1].x); for(int i = 1; i < top; i ++) sum += p[res[i]].y * (res[i-1].x-res[(i+1)%top].x); return sum / 2; }