Polygon Center of gravity problem

Source: Internet
Author: User

Time limit:MS | Memory limit:65535 KB Difficulty:5
Describe
On a polygon, take n points, which are given in the order of N points, the adjacent points in accordance with the order of the next line connected, (first and last connection), all segments do not intersect with other segments, but can be coincident, you can get a polygon or a segment or a polygon and a segment of the connected graphics;
If it is a line segment, we define an area of 0, with a center of gravity coordinate of (0,0). Now the point set of the graph consists of the area and the center of gravity of the horizontal ordinate;
Input
the first line has an integer 0<n<11, which indicates that there are n groups of data;
The first row of each group of data has an integer m<10000, indicating that the polygon has a m vertex;
Output
output the area of each polygon, the balance of the center of gravity, and retain three digits after the decimal point;
Sample input
330 10 20 331 10 00 141 10 00 0.50 1
Sample output
0.000 0.0000.500 1.0000.500 1.000


Prerequisite Knowledge:

1.1 accumulation and center of gravity

The set plane has n discrete data points (xi, yi) (i = 1, 2,., n), which
The polygon center of gravity g (. x1,. Y1) is:

  

This is the simplest and most intuitive way to find polygons. Can directly utilize discrete numbers
The X-and y-coordinates of a stronghold can be a graphical center of gravity. But the flaw is that there is no discrete
Data points around the graphics to do any processing and analysis, precision is not enough.

1.2 algorithm one: In speaking of the algorithm, we must first understand the following theorems.
Theorem 1 The vertex coordinates of the known triangle A1A2A3 ai (xi, yi) (i = 1, 2, 3). Its center of gravity coordinates are:

XG = (x1+x2+x3)/3; YG = (y1+y2+y3)/3;

Theorem 2 The vertex coordinates of the known triangle A1A2A3 ai (xi, yi) (i = 1, 2, 3). The area of the triangle is:

S = ((x2-x1) * (y3-y1)-(x3-x1) * (Y2-Y1))/2;

A1A2A3 boundary form Counterclockwise loop when Take +, clockwise time to take-.

In addition, in the process of solving, it is not necessary to consider whether the input order of points is clockwise or counterclockwise, and the division is offset.

Principle: Divide the polygon into N small area, each small area area is Ōi, the center of gravity is GI (. xi,. Yi), using the plane thin plate center of gravity formula to change the integral
into cumulative and:

    

                  

The general center of gravity formula for the polygon around discrete data points can be obtained by the principle and mathematical theorem presented above: any n-sided a1a2 with the AI (xi, yi) (i = 1, 2,., n) as the vertex. An, dividing it into N-2 triangles (1). The center of gravity for each triangle is GI (. xi,. Yi), with an area of Ōi. Then the center of gravity coordinates g (. x2,. y2) of the polygon are:

  

Figure 1 Polygon decomposition

Polygon Center of gravity problem

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.