Generate random moving nodes inside two intersecting circle
이전 댓글 표시
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.
채택된 답변
추가 답변 (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
Akande Oluwole
2016년 8월 29일
KSSV
2016년 8월 29일
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
2016년 8월 30일
카테고리
도움말 센터 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!