Problem 45196. Determine whether a given point is inside or outside a polygon
A closed polygon may be described by an N x 2 array of nodes, where the last node and the first node are the same. Each row of the array is a 2-element vector giving the x and y coordinates of a node. The polygon is described by straight-line segments that go from node to node.
In this problem, we provide you with a polygon p of this type, and with a number of points r, each having an x and y coordinate. You are to determine whether each point falls inside or outside the polygon. If the point is inside the polygon, return the value 1. If outside, return the value 0.
HINT: One way to solve this is to find a point 'p_test' that is outside of the polygon, and then to count the number of times that a line from 'r' to 'p_test' crosses the sides of the polygon.
Solution Stats
Problem Comments
-
2 Comments
Dyuman Joshi
on 25 Sep 2021
There is no input for the corresponding p variable?
Dyuman Joshi
on 4 Feb 2022
For those wondering the same as me, defining the same/global p for all the test suites initially is somehow not visible in the test suite. You can now check the value from test case #1.
Solution Comments
Show commentsProblem Recent Solvers30
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15529 Solvers
-
1242 Solvers
-
Sum all integers from 1 to 2^n
15307 Solvers
-
Flag largest magnitude swings as they occur
678 Solvers
-
Converting numbers back from extended form
117 Solvers
More from this Author2
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!