From http://blog.csdn.net/accry/article/details/6070621
First, solve the problem: what is a half plane? As the name implies, a half plane refers to half of a plane. We know that a straight line can divide a plane into two parts, so these two parts are called Two Half Planes.
Then, how do I express the half plane? In a two-dimensional coordinate system, a straight line can be expressed as AX + by + c = 0, so the two half planes can be represented as AX + by + C> = 0 and AX + by + C <0, this is the representation of the half plane.
What's more, is the half-plane interaction a magic horse? In fact, it is a system of equations that allows you to draw a region (similar to a feasible region in Linear Programming) on a coordinate system that meets several sub-formulas. The system of equations is composed of these inequalities.
What can we do with semi-plane interaction? Although the semi-plane intersection is a problem of the semi-plane, it is actually a problem of the straight line. A half plane is actually a straight line with a direction.
An important application of semi-plane intersection is to find the polygon core. Is the core of a polygon a magic horse? The core of a simple polygon is a point set inside the polygon. Any point in the set is connected to a point on the boundary of the polygon within the polygon. It is a collection of camera locations that can be monitored in all places by placing a camera head in a house, that is, the polygon core. You may often encounter the problem of determining whether a polygon has a nuclear core.
Taobao to a template
# Include <iostream> # include <stdio. h> # include <math. h> # define EPS 1e-8using namespace STD; const int maxn = 1550; int m; Double R; int ccnt, curcnt; // at this time, ccnt is the number of vertices for the final cut polygon and the number of saved vertices. struct point {Double X, Y ;}; point points [maxn], p [maxn], Q [maxn]; // The vertex (clockwise) of the read polygon. P is the array of the polygon vertices that are finally cut, and void Getline (point X, point y, double & A, double & B, double & C) // two points x and y determine a straight line A, B, and C as their coefficients {A = y. y-X. y; B = x. x-y. x; C = y. x * X. y-X. x * Y. y;} void initial () {for (INT I = 1; I <= m; ++ I) P [I] = points [I]; P [M + 1] = P [1]; P [0] = P [m]; ccnt = m; // ccnt indicates the number of vertices of the polygon obtained after final cutting, number of vertices initialized as polygon} Point intersect (point X, point y, double A, double B, double C) // calculates the intersection of A, B, C, and a straight line formed by X and Y. {double U = FABS (A * X. X + B * X. Y + C); Double V = FABS (A * Y. X + B * Y. Y + C); point pt; PT. X = (X. x * V + Y. x * u)/(U + V); PT. y = (X. y * V + Y. y * u)/(U + V); Return pt;} void cut (double A, double B, double C) {curcnt = 0; For (INT I = 1; I <= ccnt; ++ I) {If (A * P [I]. X + B * P [I]. Y + C> = 0) Q [++ curcnt] = P [I]; // C may be too small due to precision problems, so some points should not be on the right, // Therefore it should be followed to judge else {If (A * P [I-1]. X + B * P [I-1]. Y + C> 0) // If P [I-1] is on the right of the line, {// then P [I], the intersection of a straight line formed by P [I-1] with a known straight line acts as a vertex of the core (in this way, the area of the core may be reduced due to precision issues) Q [++ curcnt] = intersect (P [I], p [I-1], a, B, c);} If (A * P [I + 1]. X + B * P [I + 1]. Y + C> 0) // Same principle as above {q [++ curcnt] = intersect (P [I], p [I + 1], A, B, c) ;}}for (INT I = 1; I <= curcnt; ++ I) P [I] = Q [I]; // transfer the vertex of the saved Q core to P [curcnt + 1] = Q [1]; P [0] = P [curcnt]; ccnt = curcnt ;} void solve () {// note: the default point is clockwise. if the subject is not clockwise, the normalization direction is initial (); For (INT I = 1; I <= m; ++ I) {double A, B, C; Getline (points [I], points [I + 1], a, B, c); cut (A, B, c);}/* if you want to push R inward, use this part to replace the previous function for (INT I = 1; I <= m; ++ I) {point Ta, TB, TT; TT. X = points [I + 1]. y-points [I]. y; TT. y = points [I]. x-points [I + 1]. x; Double K = r/SQRT (TT. x * TT. X + TT. y * TT. y); TT. X = TT. x * k; TT. y = TT. y * k; TA. X = points [I]. X + TT. x; TA. y = points [I]. Y + TT. y; TB. X = points [I + 1]. X + TT. x; TB. y = points [I + 1]. Y + TT. y; Double A, B, C; Getline (TA, TB, A, B, C); cut (A, B, C );} * // area of the polygon core, double area = 0; For (INT I = 1; I <= curcnt; ++ I) area + = P [I]. x * P [I + 1]. y-P [I + 1]. x * P [I]. y; Area = FABS (area/2.0); printf ("%. 2f \ n ", area);}/* void guizhenghua () {// normalization direction, clockwise and clockwise for (INT I = 1; I <(m + 1)/2; I ++) Swap (points [I], points [M-I]);} */INT main () {int T; cin> T; while (t --) {CIN> m; int I; for (I = 1; I <= m; I ++) cin> points [I]. x> points [I]. y; points [M + 1] = points [1]; solve ();}}
Example: poj1279