Main topic: RT
Analysis: The so-called kernel can be understood as the existence of points in the polygon can be seen at this point within the polygon all the parts, of course, how to find out is the key to the problem. We know that each edge of the polygon is a boundary value, the left and right side of the edge must be part of the polygon is part of the polygon, if the polygon is clockwise, then the right side belongs to the inside, the left side belongs to the outside, if this change outside so must not see this side of the, so can be discharged. The following are the specific practices:
As shown: This polygon according to the clockwise, there are 5 vertices, respectively, is 12345, first we take the edge 12 out, found that 123 belong to the right side 12, 45 does not belong, so you can 45 throw away, but we found 12 and 34 intersect with point A, So when you find a bit on the left, you need to determine if it is connected to the line has a point of intersection, if you have to save the intersection, you can use the cross product to determine the left and right side.
The code is as follows:
#include <iostream>#include<string.h>#include<stdio.h>#include<algorithm>#include<math.h>#include<queue>using namespacestd;Const intMAXN =107;Const intOO = 1e9+7;Const DoubleEPS = 1e-Ten;intSign (Doublet) { if(T >EPS)return 1; if(Fabs (T) <EPS)return 0; return-1;}structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {} pointoperator- (ConstPoint &t)Const{ returnPoint (X-t.x, yt.y); } Double operator^(ConstPoint &t)Const{ returnx*t.y-y*T.x; }}P[MAXN],inch[MAXN];structsegment{///ax + by = CPoint S, E; DoubleA, B, C; Segment (Point S=0, point e=0): s (s), E (e) {a= S.y-e.y; b= e.x-s.x; C= e.x*s.y-s.x*e.y; } Point Crossnode (ConstSegment &t)Const{point res; Res.x= (c*t.b-t.c*b)/(a*t.b-t.a*b); Res.y= (c*t.a-t.c*a)/(b*t.a-t.b*a); returnRes; } intMul (ConstPoint &t) {///Judging direction with cross product returnSign ((e-s) ^ (tS)); }};intCutpoly (Segment L,intN) {Point TMP[MAXN]; intCNT =0; for(intI=1; i<=n; i++) { if(L.mul (inch[i]) <=0) tmp[++CNT] =inch[i]; Else { if(L.mul (inch[I1]) <0)///finding the intersection pointTMP[++CNT] = L.crossnode (Segment (inch[I1],inch[i])); if(L.mul (inch[i+1]) <0) tmp[++CNT] = L.crossnode (Segment (inch[I],inch[i+1])); } } for(intI=1; i<=cnt; i++) inch[I] =Tmp[i]; inch[0] =inch[CNT],inch[cnt+1] =inch[1]; returnCNT;}intMain () {intN; while(SCANF ("%d", &n)! = EOF &&N) {intM; for(intI=1; i<=n; i++) {scanf ("%LF%LF", &p[i].x, &p[i].y); inch[I] =P[i]; } inch[0] = p[0] =P[n]; inch[n+1] = p[n+1] = p[1]; M=N; for(intI=1; i<=n; i++) M= Cutpoly (Segment (p[i],p[i+1]), M); if(M >0) printf ("yes\n"); Elseprintf ("no\n"); } return 0;}
Rotating Scoreboard-poj 3335 (half polygon intersection for polygon cores)