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에서 Computational Geometry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by