#C9606. Point in Polygon
Point in Polygon
Point in Polygon
This problem requires you to determine if a given point is inside a polygon using the Ray Casting algorithm. The polygon is provided as a list of vertices given in order, and the point is provided as its x and y coordinate.
The ray casting algorithm works by drawing an imaginary ray horizontally from the point and then counting how many times the ray intersects with the polygon's edges. If the number of intersections is odd, the point is inside; if even, the point is outside. Note that if the point lies exactly on an edge or vertex, special considerations apply.
Note: For this problem, if the point lies exactly on a vertex of the polygon, consider it to be outside the polygon, while if it lies on an edge (but not exactly on a vertex), consider it to be inside.
inputFormat
The input begins with an integer n representing the number of vertices of the polygon. The next n lines each contain two integers which are the x and y coordinates of the polygon vertices in order. The last line contains two integers representing the x and y coordinates of the query point.
All values are separated by spaces or newlines.
outputFormat
Output a single line containing either True
or False
indicating whether the point is inside the polygon.
4
1 1
4 1
4 4
1 4
2 2
True
</p>