就是把一个n边形 分割为n-2个三角形 然后相加
然后求每个三角形的面积
设一个三角形的三个点x1,y1,x2,y2,x3.按逆时针给出。
那么这个三角形的面积可以表示为s=((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2;
贴上代码
#include <stdio.h>#include <math.h>int main(){double x1,x2,x3,y1,y2,y3,s;int n;while(scanf("%d",&n)!=EOF&&n){s=0;scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);for(int i=0;i<n-2;i++){scanf(" %lf %lf",&x3,&y3);s=s+((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2;x2=x3,y2=y3;}printf("%.1lf\n",s);}return 0;}
,我不但的回首,伫足,然后时光扔下我轰轰烈烈的向前奔去。