Generate random moving nodes inside two intersecting circle
Mostrar comentarios más antiguos
Hi everyone, I am trying to generate random points inside a circle given the radius and the center. If anyone has a sample code or can help me with this. thanks.
Respuesta aceptada
Más respuestas (1)
clc; clear all ;
C = [0 0] ; % center of the circle
R = 1. ; % Radius of the circle
N = 100 ;
th =linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(2)+R*sin(th) ;
plot(xc,yc,'b') ;
hold on
axis equal
% Generate random numbers using polar coordinates
for i = 1:N
r = R * sqrt(rand(1,1)) ;
theta = 2 * pi * rand(1,1) ;
x = r * cos(theta) ;
y = r * sin(theta) ;
plot(x,y,'.r')
drawnow
end
3 comentarios
Akande Oluwole
el 29 de Ag. de 2016
KSSV
el 29 de Ag. de 2016
Two circles have different center? You have two circles of same radii and they intersect..you will get a oval shape, you want random numbers inside this? Ask question clearly.
Akande Oluwole
el 30 de Ag. de 2016
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!