Solving the area (inside the plane) of any polygon and solving the area plane

Source: Internet
Author: User

Solving the area (inside the plane) of any polygon and solving the area plane

The calculation of the polygon in the plane, that is, the calculation of the polygon in the plane coordinate system. It is known that the coordinates of each point are sequential, clockwise or clockwise. Calculate the area based on the given coordinates.

Here is a simple method to calculate the area of a polygon by using integral points. The area can be obtained based on the sum of points on the X axis of each edge. Note that if you calculate points and obtain area in clockwise direction, the opposite number of area is counter-clockwise. If you do not understand it, you can verify it by yourself. The principle is very simple and is not described in detail.

1 # include <iostream> 2 using namespace std; 3 // calculate the integral 4 double cal of an edge (int x1, int y1, int x2, int y2) {5 return (x2-x1) * (y1 + y2)/2.0; 6} 7 int main () {8 int x0, y0, x1, y1, x2, y2; 9 int n; 10 while (cin> n & n! = 0) {// calculate the points of each edge cyclically 11 cin> x1> y1> x2> y2; 12x0 = x1; y0 = y1; 13 double sum = 0; 14 sum + = cal (x1, y1, x2, y2); 15 for (int I = 3; I <= n; I ++) {16x1 = x2; y1 = y2; 17 cin> x2> y2; 18 sum + = cal (x1, y1, x2, y2 ); 19} 20 sum + = cal (x2, y2, x0, y0); // link points of the last vertex and the first vertex. 21 printf ("%. 1f \ n",-sum); 22} 23 return 0; 24}

 

Related Article

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.