Preliminary calculation of geometry

Source: Internet
Author: User

Well, because I am a computational geometry slag, so the title is to write a preliminary good ...

① Polygon Area poj3907

Find a point and cross-product the polygon's adjacent vertices. Add together to find the absolute value.

#include <iostream>#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<string.h>#include<vector>#include<math.h>#include<limits>#include<Set>#include<map>using namespacestd;intN;Doublex[2333333],y[2333333];intMain () { while(SCANF ("%d",&N), N) { for(intI=0; i<n;i++) scanf ("%LF%LF", x+i,y+i); Doublemx=2000000000, my=2000000000;  for(intI=0; i<n;i++) Mx=min (Mx,x[i]), my=min (my,y[i]); --MX; --my; Doubleans=0;  for(intI=0; i<n;i++)        {            DoubleX1=X[I]-MX, y1=y[i]-my; Doublex2=x[(i+1)%n]-mx, y2=y[(i+1)%n]-my; Ans+=x1*y2-y1*x2; } ans/=2; if(ans<0) ans=-ans; printf ("%.0lf\n", ans); }}

② whether the point is inside the polygon zoj1081

Classic problem, as long as the point in one direction to do a ray (the level is prone to accidents), and then count the intersection of the polygon edge number.

It can be found that if the ray does not pass through the polygon vertices, it is only possible to judge the parity of the intersection.

Preliminary calculation of geometry

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.