dividing a circle into equal n parts and then generate random point inside each part

I am trying to divide a circle (given the radius and the center)into n parts and then generate random points inside each part . If anyone has a sample code or can help me with this, thanks in advance.

 Respuesta aceptada

x0=2;
y0=1;
r=1;
teta=-pi:0.01:pi;
x=r*cos(teta)+x0
y=r*sin(teta)+y0
plot(x,y)
hold on
scatter(x0,y0,'or')
axis square
%----------------------------------------
% divide your circle to n sectors
n=8
tet=linspace(-pi,pi,n+1)
xi=r*cos(tet)+x0
yi=r*sin(tet)+y0
for k=1:numel(xi)
plot([x0 xi(k)],[y0 yi(k)])
hold on
end

16 comentarios

Thanks Aziz,
then after the dividing to n parts how can i generate random n points in each part
how can i generate one random point in each part (each part contains only one point)
Generate a random angle for each interval of angles defined in the vector tet, and generate a random radius <=r
m=numel(tet)
rteta=arrayfun(@(x) tet(x)+rand*(tet(x+1)-tet(x)),1:m-1)
rand_r=rand(1,m-1)*r
xr=rand_r.*cos(rteta)+x0
yr=rand_r.*sin(rteta)+y0
scatter(xr,yr,'g','MarkerFaceColor','c')
How to find no of random points drawn in a circle?
The number of random points drawn by the above code is m-1, which is length(xr) or the length of yr or rand_r, or the number of elements of tet minus 1.
How can I generate n points inside each sector? and the distance between any two adjacent points should not exceed d distance??
"How can I generate n points inside each sector"
Are the sectors circular? If so then use techniques like the above to generate x and y coordinates inside a circle with a radius the same as the radius of the sector, and then add the coordinates of the center of the circle to each of the generated x and y values.
The sectors not circle. I used the above code but when I tried to update the number of nodes (I just replaced "m-1" by 25), I got this error
Attempted to access tet(10); index out of bounds because numel(tet)=9.
Error in @(x)tet(x)+rand*(tet(x+1)-tet(x))
What shape are the sectors?
You should change
n=25;
and leave the linspace() the way it is.
The shape of the sectors is circular sector I want
% n=8; % the number of sectors
so I didn't change it. what I want 8 sectors with 3 points in each sector, except the last one must have 4 points.
How could I space the points in a specific sector of the circle equally (instead of random)?
You need to decide whether the "equal" spacing is by radius or by angle or by area. Or if you are trying to inscribe an equilateral triangular mesh within the sector of the circle.
The points should be equally spread across the area (=a sector of the circle)
Probably the easiest way to do equal spacing by area is to convert to Cartesian coordnates, and find grid points that are within the boundaries of the sector.

Iniciar sesión para comentar.

Más respuestas (1)

2 comentarios

how can i generate one random point in each part (each part contains only one point)
Like I said, use the FAQ. Just modify it to use the angles you want. Below is does it for a sector going between pi/4 and 3pi/4:
% Create a random set of coordinates in a circle.
% First define parameters that define the number of points and the circle.
n = 5000;
R = 20;
x0 = 50; % Center of the circle in the x direction.
y0 = 90; % Center of the circle in the y direction.
% Now create the set of points.
% For a full circle, use 0 and 2*pi.
%angle1 = 0;
%angle2 = 2*pi;
% For a sector, use partial angles.
angle1 = pi/4;
angle2 = 3*pi/4;
t = (angle2 - angle1) * rand(n,1) + angle1;
r = R*sqrt(rand(n,1));
x = x0 + r.*cos(t);
y = y0 + r.*sin(t);
% Now display our random set of points in a figure.
plot(x,y, '.', 'MarkerSize', 5)
axis square;
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
fontSize = 30;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Random Locations Within a Circle', 'FontSize', fontSize);
Just do this once for every sector you want to fill.

Iniciar sesión para comentar.

Categorías

Más información sobre Polar Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 19 de Oct. de 2013

Comentada:

el 24 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by