dividing a circle into equal n parts and then generate random point inside each part
Mostrar comentarios más antiguos
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.
1 comentario
the cyclist
el 19 de Oct. de 2013
Is this a school assignment? What have you tried so far?
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 19 de Oct. de 2013
1 voto
2 comentarios
Hassan
el 19 de Oct. de 2013
Image Analyst
el 19 de Oct. de 2013
Editada: Image Analyst
el 19 de Oct. de 2013
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.
Categorías
Más información sobre Polar Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!