Poj 3335 rotating Scoreboard (solving polygon kernel)

Source: Internet
Author: User

Question link: http://poj.org/problem? Id = 3335

This question is to give you a polygon, so that you can determine whether there is a point (or an area) inside the polygon so that you can observe all the places inside the polygon as long as it is inside the area.

The edges of a polygon are not transparent;

A well-understood Algorithm for this topic is to continuously cut polygon, maintain a polygon point set that may be in the kernel area, and finally determine that the number of points is greater than 0 to meet the conditions, otherwise the conditions will not be met.

If the current vertex is on the side of the test line, add the vertex to the set of the current vertex. If not, if the vertex is the first or the last vertex, then the first and second straight lines and the current test straight lines

There must be two intersections, so these two intersections must be in the current qualified set! Pay attention to the previous steps!

For specific solutions, refer to the following code:

I learned later that this method was originally called semi-flat transaction. Sorry, I used it directly when I didn't know it. I started to know the method name and didn't know what was going on, why is this name?

Suddenly, this figure has several edges. the straight line of each edge splits the plane into two parts, now you need to calculate the N * 2 portions of the common part of the N plane whose median is positive.

The common part is the polygon kernel. Well, it hasn't been reflected yet!

Another huge blog: http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html

# Include <iostream> # include <stdio. h> # include <string. h >#include <cmath> # include <algorithm> # define maxn 105 struct node {Double X; Double Y;} Point [maxn], p [maxn], Q [maxn]; int n, m; Double A, B, C; void Getline (node X, node y) // obtain the straight line AX + by + c = 0 {A = y. y-x.y, B = x. x-y.x; C = y. x * X. y-x.x * Y. y;} node intersect (node X, node y) // obtain the intersection of the straight lines AX + by + c = 0 and X and Y {double U = FABS (A * X. X + B * X. Y + C); Double V = FABS (A * Y. X + B * Y. Y + C); node ans; ans. X = (X. x * V + Y. x * u)/(U + V); ans. y = (X. y * V + Y. y * u)/(U + V); Return ans;} int cut_line () {int I, j, k; int num = 1; for (I = 1; I <= m; I ++) {If (A * P [I]. X + B * P [I]. Y + C> = 0) {q [num ++] = P [I];} else {If (A * P [I-1]. X + B * P [I-1]. Y + C> 0) Q [num ++] = intersect (P [I-1], p [I]); If (A * P [I + 1]. X + B * P [I + 1]. Y + C> 0) Q [num ++] = intersect (P [I], p [I + 1]) ;}} for (I = 1; I <num; I + +) P [I] = Q [I]; P [0] = P [num-1]; P [num] = P [1]; M = num-1; return 0;} int main () {int T, I, J, K; scanf ("% d", & T); While (t --) {scanf ("% d", & N); for (I = 1; I <= N; I ++) scanf ("% lf ", & point [I]. x, & point [I]. y); M = N; point [0] = point [N]; point [n + 1] = point [1]; for (I = 0; I <= m; I ++) P [I] = point [I]; P [M + 1] = P [1]; for (I = 1; I <= N; I ++) {Getline (point [I], point [I + 1]); cut_line ();} If (M = 0) printf ("NO \ n"); else printf ("Yes \ n");} return 0 ;}

Poj 3130: http://poj.org/problem? Id = 3130

This question is the same as the above, but the given point is counter-clockwise, so you can directly use the above Code by changing the above Code bigger than the number smaller than the number, or directly converting it into a clockwise!

# Include <iostream> # include <stdio. h> # include <string. h >#include <cmath> # include <algorithm> # define maxn 105 struct node {Double X; Double Y;} Point [maxn], p [maxn], Q [maxn]; int n, m; Double A, B, C; void Getline (node X, node y) // obtain the straight line AX + by + c = 0 {A = y. y-x.y, B = x. x-y.x; C = y. x * X. y-x.x * Y. y;} node intersect (node X, node y) // obtain the intersection of the straight lines AX + by + c = 0 and X and Y {double U = FABS (A * X. X + B * X. Y + C); Double V = FABS (A * Y. X + B * Y. Y + C); node ans; ans. X = (X. x * V + Y. x * u)/(U + V); ans. y = (X. y * V + Y. y * u)/(U + V); Return ans;} int cut_line () {int I, j, k; int num = 1; for (I = 1; I <= m; I ++) {If (A * P [I]. X + B * P [I]. Y + C <= 0) {q [num ++] = P [I];} else {If (A * P [I-1]. X + B * P [I-1]. Y + C <0) Q [num ++] = intersect (P [I-1], p [I]); If (A * P [I + 1]. X + B * P [I + 1]. Y + C <0) Q [num ++] = intersect (P [I], p [I + 1]) ;}} for (I = 1; I <num; I + +) P [I] = Q [I]; P [0] = P [num-1]; P [num] = P [1]; M = num-1; return 0;} int main () {int T, I, J, K = 0; // scanf ("% d", & T ); while (scanf ("% d", & N), n) {for (I = 1; I <= N; I ++) scanf ("% lf ", & point [I]. x, & point [I]. y); M = N; point [0] = point [N]; point [n + 1] = point [1]; for (I = 0; I <= m; I ++) P [I] = point [I]; P [M + 1] = P [1]; for (I = 1; I <= N; I ++) {Getline (point [I], point [I + 1]); cut_line ();} If (M = 0) printf ("0 \ n"); else printf ("1 \ n");} return 0 ;}

The following describes the conversion from: http://www.cnblogs.com/ka200812/archive/2012/01/20/2328316.html

Polygon Kernel Algorithm

What is the polygon kernel?

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.

 

For example, the first graph has a kernel, such as the black dot, and the second graph does not have a kernel. No matter where it is, there is always a region that cannot be seen.

 

So how can we obtain this kernel interval? The general algorithm is to use two straight lines to continuously cut the polygon and cut to the end, that is, the kernel interval.

We all know that a straight line can cut the plane into two regions. Assume that the linear equation is

Ax + by + c = 0, then the two planes can be expressed as AX + by + C> = 0 and AX + by + C <0

 

How can we use a program to cut a polygon in a straight line?

The process is as follows:

1. Store the original polygon point set in a clockwise or counterclockwise order.

2. Take two consecutive points in order to form a straight line. Use this line to cut the original polygon.

First, let me assume that the point is stored clockwise,

In this case, the point set of a polygon is {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

 

Take point 1 and form a straight line AX + by + c = 0 with point 2. At this time, the point in the vertex concentration is brought into the equation AX + by + C at one time, the obtained values are greater than or equal to 0, indicating that all vertices are on the same side of the straight line, and the point set remains unchanged.

 

Take points 2 and 3 to form a straight line. Similarly, the points in the vertex set are sequentially brought into the equation AX + by + C. At this time, the results of the 4 and 5 points are less than 0, the value of other points is still greater than or equal to 0. At this time, the points 4 and 5 are cut out of the polygon. Therefore, only {1, 2, 3, 6, 7, 8, 9, 10 are left, x}, (x is the intersection of line 23 and line 56)

 

And so on, always execute to point 10 and point 1, then the kernel set will be obtained.

 

It is worth noting that the figures in this example are special, all at right angles. If the figures are casual, when a point is determined to be out of the polygon range, we should also consider whether there is any intersection between the straight line formed by the two adjacent points and the ax + by + C. If there is an intersection, these intersections should be added to the updated vertex set, for example, after a straight line composed of vertices 2 and vertices 3 is executed in the example, the point set is {1, 2, 3, 6, 7, 8, x}, where 3 and X are the result.

 

Also, why is it enough to execute all vertices one by one and construct a new point set from the remaining vertices? The answer is that the point is clockwise or clockwise ~~~

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.