how to locate/extract users in circle from randomly distributed many points..?

1 回表示 (過去 30 日間)
Hi everyone. I have randomly deployed users in a hexagon and circle. The problem i am facing is to locate the users which are in circle, and to find the distance of those users/points from the center of circle. Is there any way that only the users which are in circle can be extracted as shown in figure? Kindly help me with this.

採用された回答

Image Analyst
Image Analyst 2016 年 8 月 28 日
You must know the circle you're talking about. So let's say it is at location (xCenter, yCenter) and has radius R. I'm going to assume that when you said you "randomly deployed users in hexagon and circle" that you actually did NOT do that since you said some may not be inside the circle and you need to know which are not in the circle. So you can use sqrt() to find the distance of each user location from the center. I'll assume the users' locations are in vectors xUser and yUser. So, to find the distance of all users from the known center of the circle, you do:
distances = sqrt((xUser - xCenter) .^ 2 + (yUser - yCenter) .^ 2);
Now to find out which indexes are inside the circle, look for which distances are less than R
usersInsideCircle = distances < R;
That is a logical vector. If you want to extract the x and y of users in the circle from the entire list, use that logical index:
xInCircle = xUsers(usersInsideCircle);
yInCircle = yUsers(usersInsideCircle);
For the hexagon you might find it easier to use the inpolygon() function:
for k = 1 : length(xUsers)
usersInsideCircle(k) = inpolygon(xUsers(k), yUsers(k), xVertices, yVertices);
end
where xVertices and yVertices are the 6 vertices of your hexagon. You could use that for the circle also if you wanted to supply all the edge coordinates of the circle perimeter though there is a slight chance that a point could be inside the theoretical circle but outside the "circle" approximated by a bunch of vertex points.
  8 件のコメント
Image Analyst
Image Analyst 2016 年 10 月 12 日
Sorry, but no it doesn't. Just look at it in the dubugger. usersInsideCircle is a logical vector of true/1, and false/0. It is not an array of doubles with various floating point distances. You'd better check again.
FYI to get the distances themselves, you'd have to use usersInsideCircle as a logical index to distances, like this:
distancesInside = distances(usersInsideCircle);
THAT will be a vector of only the distances of users inside the circle and won't include distances of users outside the circle.
ammara khurshid
ammara khurshid 2016 年 10 月 12 日
i was doing in wrong way. now worked. thank you.

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 8 月 28 日
pdist2() with the second argument being the coordinates of the center of the circle. Any of the points within the cutoff radius are "in" the circle and you will know the distance.
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 8 月 28 日
The first argument would be the location of the points. You do know the location because you used random distribution to generate the locations.
Your figure does not appear to be attached.
Is your task to figure out which of the already-generated positions are within a particular circle, or is your task to generate positions confined to a particular circle like https://www.mathworks.com/matlabcentral/answers/294-generate-random-points-inside-a-circle
ammara khurshid
ammara khurshid 2016 年 8 月 28 日
here is the figure i mentioned earlier

サインインしてコメントする。


Image Analyst
Image Analyst 2016 年 8 月 28 日
If you have two sets of points, red crosses and blue crosses, and want to find corresponding points, like which point in blue best matches a given point in red, this is not easy, and there may be no unique solution. There are many algorithms and you can search for "point matching algorithm" for articles: https://www.google.com/#q=point+matching+algorithm

カテゴリ

Help Center および File ExchangePolygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by