Question regarding finding the boundaries (vertices) of a series of data points on a 2D space

3 次查看(过去 30 天)
Hello,
I have a series of x,y data that form a distinct closed shape (this shape is not a geometrical shape like circle, sphere, etc.). My problem is how to test if a new given point would fall inside or outside this shape. It seems that "inpolygon" function of matlab can answer my question, but that function requires the vertices of the object but my data is x/y info of all points that form the shape. Is there an already available function that I can use to find the vertices of these data? also, do you have any other suggestion instead of "inpolygon" for inside/outside problem? I greatly appreciate your response.
Regards, NF
  2 个评论
Sven
Sven 2011-11-15
So when you say "my data is x/y info of all points that form the shape", you mean that you *don't* have vertex data of the *boundaries*, you instead have data of every point *inside* the shape?
Are all of your points in a regular grid? Can you use bwboundaries?
It will certainly help if you can show a small piece of code that demonstrates your problem.
Noushin Farnoud
Noushin Farnoud 2011-11-15
Thanks Sven for your comment. You are right, I have every point inside the shape but not the vertices (or boundary). I can not simulate the exact data set with Matlab, but below is an example:
SIGMA1 =[0.05 0;0 0.05];
SIGMA2 =[0.05 0;0 0.05];
MU1 =[1 2];
MU2 =[2.005 2];
X = [mvnrnd(MU1,SIGMA1,2000);mvnrnd(MU2,SIGMA2,2000)];
scatter(X(:,1),X(:,2));ylim([- 3 3]);
I like to find the vertices of X so I can pass these vertices to 'inpolygon' function to decide if a given point (e.g., (-1,3)) is inside this shape or outside.
Thanks, NF

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2011-11-15
Have you taken a look at the convex hull, convhull()? That will give you the coordinates of the exterior perimeter points, just as if you have wrapped a rubber band around your points.
  1 个评论
Noushin Farnoud
Noushin Farnoud 2011-11-15
I have tried convexthull(), but because of the asymmetrical shape of my data (one side is tilted) it does not fit my shape properly. The problem comes when I use the generated border with inpolygon() function: many tested points that are outside the shape are found by inpolygon() to be inside the new convexhull generated border.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by