Problem 198. Are you in or are you out?
Given vertices specified by the vectors xv and yv, and a single point specified by the numbers X and Y, return "true" if the point lies inside (or on the boundary) of the polygon defined by the vertices.
Example:
% The specified point is the center of the unit square: xv = [0 1 1 0]; yv = [0 0 1 1]; X = 0.5; Y = 0.5;
inside(xv,yv,X,Y) -----> true
Solution Stats
Problem Comments
-
3 Comments
The test suit only tests points that are inside or outside but not on the boundary of the polygon
Cyclist, this was a pretty tough problem to solve without resorting to Googling a solution or something similar. I ended up with a function that will work for any n-sided polygon. Thanks for the weekend challenge.
Maybe, thinking this problem in topology aspect is useful.
Solution Comments
Show commentsProblem Recent Solvers234
Suggested Problems
-
Return the 3n+1 sequence for n
8271 Solvers
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
1813 Solvers
-
1584 Solvers
-
Project Euler: Problem 1, Multiples of 3 and 5
3169 Solvers
-
600 Solvers
More from this Author23
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!