Computational geometric Summary

Source: Internet
Author: User

Set N discrete data points (xi, yi) (I = 1, 2,., n) on the plane.
Polygon center of gravity G (. x1,. y1) is:



Sum:




# Include <iostream> # include <algorithm> # include <cstring> # include <cstdio> using namespace std; struct Point {double x, y ;}; // calculate the Area double Area (const Point p0, const Point p1, const Point p2) using cross product {// In addition, you do not need to consider whether the point input sequence is clockwise or counterclockwise. After division, it is offset. Return (p0.x * p1.y + p1.x * p2.y + p2.x * p0.y-p1.x * p0.y-p2.x * p1.y-p0.x * p2.y)/2.0;} int main () {int T, n; scanf ("% d", & T); while (T --) {Point p0, p1, p2; double area = 0, suma = 0, sumx = 0, sumy = 0; scanf ("% d", & n); scanf ("% lf", & p0.x, & p0.y); scanf ("% lf ", & p1.x, & p1.y); for (int I = 2; I <n; ++ I) {scanf ("% lf", & p2.x, & p2.y ); area = Area (p0, p1, p2); suma + = area; sumx + = (p0.x + p1.x + p2.x) * area; sumy + = (p0.y + p1.y + p2.y) * area; p1 = p2;} printf ("%. 2lf %. 2lf \ n ", sumx/suma/3, sumy/suma/3);} return 0 ;}






Zookeeper

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.