Generate random moving nodes inside two intersecting circle
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (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 commentaires
Akande Oluwole
le 29 Août 2016
KSSV
le 29 Août 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
le 30 Août 2016
Catégories
En savoir plus sur Polar Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!