测量坐标系中单个多边形面积解析法计算的程序源代码
#include"iostream.h"
double calarea(double *x,double *y,int N)
{ double sum=0;
for(int i=0;i<N;i++)
{if(i<N-1)
sum+=x[i]*y[i+1]-x[i+1]*y[i];
else
sum+=x[i]*y[0]-x[0]*y[i];
cout<<"sum中间数据:"<<sum<<endl;
}
return sum/2.0;
}
void main()
{ int N,i;
cout<<"请输入你要计算多边形的顶点个数"<<endl;
cin>>N;
if(N>100)
{cout<<"你输入的N值超限,请重新输入"<<endl;
cin>>N;
}
double x[100];
double y[100];
cout<<"请分别输入你用于计算的坐标(x y)"<<endl;
for(i=0;i<N;i++)
{cout<<"请输入第"<<i+1<<"个坐标"<<endl;
cin>>x[i]>>y[i];
}
cout<<"你输入的坐标是这样的:"<<endl;
for(i=0;i<N;i++)
cout<<x[i]<<" "<<y[i]<<endl;
cout<<"您的最终面积数据是:"<<calarea(x,y,N)<<endl;
}