Method One:
float Area_of_polygon (int vcount,float x[],float y[])
{
int i;
float S;
if (Vcount <3) return 0;
s=y[0]* (x[vcount-1]-x[1]);
for (I=1;i <vcount;i++)
s+=y[i]* (x[(i-1)]-x[(i+1)%vcount]);
return S/2;
}
Method Two:
Algorithmic version of Daniel Starfish original
Public float Area_of_polygon (point[] apoints)
{
if (Apoints.length < 3) return 0;
float s = apoints[0]. Y * (Apoints[apoints.length-1]. X-APOINTS[1]. X);
for (int i = 1; i < apoints.length; i++)
s + = Apoints[i]. Y * (apoints[(i-1)). X
apoints[(i + 1)% apoints.length]. X);
Return System.Math.Abs (S/2);
}
private void Button1_Click (object sender, EventArgs e)
{
Text = Area_of_polygon (new point[] {
New Point (0, 0), new Point (0, 10),
New Point (Ten), New Point (10, 0)}). ToString ();
}
Method Three:
Creating polygons is actually specifying the order of these vertices
After determining the order, it is assumed that p0, P2, ...., pn-1
Then the area of the polygon can be calculated simply by the following formula
float area = 0;
for (int i=0, j=1; I <n; i++, J + +)
{
j = j% n; Because when j=n, I need to get J back 1.
Area + = p[i].x*p[j].y-p[i].y*p[j].x;
}
Areas = fabs (area * 0.5);//Take 1/2 and then take the absolute value, because the size of the calculated values may be negative (when each vertex is arranged clockwise)
Math: Knowing the coordinates of each vertex of N-shape, seeking area