3 3 0 1 0 2 0 3 3 1 1 0 0 0 1 4 1 1 0 0 0 0.5 0 1
0.000 0.000 0.500 1.000 0.500 1.000
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
struct Poit
{
double x;
double y;
};
double Area_3(Poit C,Poit A,Poit B);
int main()
{
int m;
cin>>m;
for(int i=0;i<m;i++)
{
int n;
cin>>n;
vector<Poit>a;
Poit G={0,0}; //G為重心
double sum_area=0; //總面積
double Gxy; //重心橫縱坐標和
for(int j=0;j<n;j++)
{
int x0,y0;
cin>>x0>>y0;
Poit p={x0,y0};
a.push_back(p);
}
for(int k=0;k<n;k++)
{
G.x=G.x+a[k].x;
G.y=G.y+a[k].y;
}
G.x=G.x/n;
G.y=G.y/n;
Gxy=G.x+G.y;
a.push_back(a[0]); //最後的和0重和;
for(int h=0;h<n;h++) //求總面積
{
sum_area=sum_area+Area_3(a[h],a[h+1],G);
}
cout<<sum_area<<" "<<Gxy<<endl;
}
return 0;
}
double Area_3(Poit C,Poit A,Poit B) //為了保證角A為銳角;B為重心;
{
double a,b,c;
double area;
a=sqrt(pow((B.x-C.x),2)+pow((B.y-C.y),2));
b=sqrt(pow((A.x-C.x),2)+pow((A.y-C.y),2));
c=sqrt(pow((A.x-B.x),2)+pow((A.y-B.y),2));
double cos_A=(pow(b,2)+pow(c,2)-pow(a,2))/(2*b*c);
double sin_A=abs(sqrt(1-pow(cos_A,2)));
area=0.5*b*c*sin_A;
return area;
}