Area Formula of Any Polygon

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.