Hello, prompt please algorithm of actions when implementing the method of determining points of the polygon **the Given number of revolutions**. Thank you for your answer.

asked April 4th 20 at 00:35

2 answers

answered on April 4th 20 at 00:37

mmm. such a difficult task. a ray from a point, parallel to any axis. count how many times intersects with the sides of the polygon. if the number of intersections is even, the answer is one, if the number is odd the answer is another.

the answer is easily searched by the search engine

the answer is easily searched by the search engine

answered on April 4th 20 at 00:39

This is a standard task of geodesy at the entry point in the polygon is solved by slanting the multiplication of two vectors.

In fact, we move all the segments of a polygon and looks which side of the segment the point lies in. Count the number of all cases when it lies to the right of the line (i.e. intersects when turning), filter out all segments that lie above or below the point. If the number on the right is even or zero, then the point in the polygon is not included, if odd, therefore lies inside the polygon.

Code is solved in five lines.

PS: found my answer two years ago)

In fact, we move all the segments of a polygon and looks which side of the segment the point lies in. Count the number of all cases when it lies to the right of the line (i.e. intersects when turning), filter out all segments that lie above or below the point. If the number on the right is even or zero, then the point in the polygon is not included, if odd, therefore lies inside the polygon.

Code is solved in five lines.

PS: found my answer two years ago)

Hello) thank you for your answer. Yes, that got rid of one more solution, now trying to deal with it, the second task

commented on April 4th 20 at 00:42

commented on April 4th 20 at 00:42

@fiona , That's just the code not working in some cases - if the point lies outside and on the same horizontal, and only the lowest point of the polygon. Ie horizontal beam for the polygon at the vertex. In this case should be 0 or 2 intersections, and your method will count exactly one.

It's because you ignore every segment second end (in the order), and should be ignored only Nizhnee point (or just the top). commented on April 4th 20 at 00:45

It's because you ignore every segment second end (in the order), and should be ignored only Nizhnee point (or just the top). commented on April 4th 20 at 00:45

@coy, Yes, You are right, the error is. To fix it, short of examples in the Internet. commented on April 4th 20 at 00:48

Find more questions by tags AlgorithmsGraphics

- wyatt_Mante commented on April 4th 20 at 00:40

Another of the little tricks necessary to clarify what to do if a ray passes through a polygon vertex: consider the intersection of only the lower ends of the segments. Then this beam can count from 0 to 2 intersections with the polygon and all edge cases are properly measured (that Is, if the beam touches the vertices of the polygon or intersects the boundary at the top). Also, just ignore the horizontal cuts. - coy commented on April 4th 20 at 00:43

- wyatt_Mante commented on April 4th 20 at 00:46

The first page in the first photo is not clear that describes. I think there is masturbirovala and calculated the coordinates of the points in the new coordinate system (on the screen? 1280x960 new borders, like the screen resolution). - coy commented on April 4th 20 at 00:49

- wyatt_Mante commented on April 4th 20 at 00:52

In principle, this is a very similar solution, but then again, a lot of instances, with the intersection point. Need to watch the neighboring vertices, and where they are from beam, otherwise it is possible to incorrectly calculate the speed (If the beam just passes through the vertex, and 2 adjacent on opposite sides - that is one turn in + or -, If 2 adjacent vertices on one side of the beam, it is 0 rpm). - coy commented on April 4th 20 at 00:55