Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Image Analyst
Image Analyst el 28 de Ag. de 2016
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 comentarios
Image Analyst
Image Analyst el 12 de Oct. de 2016
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 el 12 de Oct. de 2016
i was doing in wrong way. now worked. thank you.

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 28 de Ag. de 2016
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 comentarios
Walter Roberson
Walter Roberson el 28 de Ag. de 2016
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

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 28 de Ag. de 2016
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

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by