标签:
//任意多边形的面积计算
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
typedef std::pair<double ,double> point;
#pragma warning(disable:4244)
double det(point p0,point p1,point p2)
{
return (p1.first-p0.first)*(p2.second-p0.second)-(p1.second-p0.second)*(p2.first-p0.first);
}
double ploygon_area(int n,point p[])
{
double s=0.0f;
int i=1;
for(;i < n-1;i++)
s += det(p[0],p[i],p[i+1]);
return 0.5*fabs(s);
}
int main()
{
int i,n;
double s;
point p_xy[101];
while(cin >> n && n != 0)
{
for(i=0; i<n; i++){
//cout<<endl<<"points["<<i<<"]=";
cin>>p_xy[i].first>>p_xy[i].second;
}
s=ploygon_area(n, p_xy);
cout << setiosflags(ios::fixed);
cout.precision(1);
cout << s << std::endl;
}
return 0;
}
http://blog.csdn.net/hemmingway/article/details/7814494 ---->要了解原理的请看这里。
标签:
原文地址:http://www.cnblogs.com/lishuhuakai/p/4855424.html