#include <iostream>
#include <cmath>
#include <cmath>
const int NUM = 6;
//多边形的各边不能相交,不然计算会出错
//面积为正可以判断多边型正面,面积为负表示多边形背面
double GetArea( POINT *pPoint, int nNum )
{
double S = 0;
for(int i=0; i<nNum-1; i++)
S+=pPoint[i].x*pPoint[i+1].y-pPoint[i+1].x*pPoint[i].y;
S += pPoint[nNum-1].x*pPoint[0].y - pPoint[0].x*pPoint[nNum-1].y;
S /= 2.0;
return S;
}
//多边形的各边不能相交,不然计算会出错
//面积为正可以判断多边型正面,面积为负表示多边形背面
double GetArea( POINT *pPoint, int nNum )
{
double S = 0;
for(int i=0; i<nNum-1; i++)
S+=pPoint[i].x*pPoint[i+1].y-pPoint[i+1].x*pPoint[i].y;
S += pPoint[nNum-1].x*pPoint[0].y - pPoint[0].x*pPoint[nNum-1].y;
S /= 2.0;
return S;
}
int main()
{
POINT points[NUM] = {
{0, 0},
{3, 12},
{5, 6},
{8, 8},
{10, 2},
{4, 4}
};
double ss=0;
ss = fabs(GetArea(points, NUM));
std::cout<<ss<<std::endl;
return 0;
}
{
POINT points[NUM] = {
{0, 0},
{3, 12},
{5, 6},
{8, 8},
{10, 2},
{4, 4}
};
double ss=0;
ss = fabs(GetArea(points, NUM));
std::cout<<ss<<std::endl;
return 0;
}