Set Ω to M edge shape (for example), vertices are arranged along the boundary forward, and the coordinates are
Create a polygon area vector graph of Ω.
A triangle is formed by two vertices adjacent to a polygon, and the area of the triangle is obtained by the outer product of two plane vectors composed of three vertices.
Area Formula of Any Polygon
The calculation of the polygon formula has no relationship with the selection of the origin. Generally, you can select a vertex (0, 0) or a polygonFirst point(This is more intuitive. It looks like dividing Polygon into triangles and adding them. You can draw a graph yourself.
// Calculate the area of any polygon # include <iostream> # include <utility> # include <cmath> Using STD: cout; Using STD: CIN; Using STD: Endl; typedef STD: pair <double, double> point; # pragma warning (Disable: 4244) Double det (point P0, Point P1, point P2) {return (p1.first-second first) * (p2.second-second)-(p1.second-second) * (p2.first-second 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 argc, char * argv []) {int I, n; double S; point * points = NULL; cout <"Enter the number of edges of the polygon <n>:"; CIN> N; If (n <2) {exit (1 );} points = (point *) malloc (N * sizeof (point); for (I = 0; I <n; I ++) {cout <Endl <"points [" <I <"] ="; CIN> points [I]. first> points [I]. second;} s = ploygon_area (n, points); cout <"the area is:" <S <STD: Endl; If (points) Free (points ); return 1 ;}