Generate random moving nodes inside two intersecting circle
Show older comments
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.
Accepted Answer
More Answers (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 Comments
Akande Oluwole
on 29 Aug 2016
KSSV
on 29 Aug 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
on 30 Aug 2016
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!