Generate random coordinates around a circle
조회 수: 1 (최근 30일)
이전 댓글 표시
How can I generate 15 random 2-D coordinates around a circle of radius R with the center of the circle being a defined [x y] 2-D coordinate? Thanks
댓글 수: 4
답변 (2개)
Azzi Abdelmalek
2013년 7월 31일
편집: Azzi Abdelmalek
2013년 8월 1일
x0=10; % x0 an y0 center coordinates
y0=20;
radius=10; % radius
angle=-pi:0.1:pi;
angl=angle(randperm(numel(angle),15));
r=rand(1,15)*radius;
x=r.*cos(angl)+x0;
y=r.*sin(angl)+y0;
xc=radius.*cos(angle)+x0;
yc=radius.*sin(angle)+y0;
scatter(xc,yc,'.r')
hold on
scatter(x,y)
xlim([-radius radius]+x0)
ylim([-radius radius]+y0)
axis square
hold off
댓글 수: 2
Richard Brown
2013년 8월 1일
편집: Richard Brown
2013년 8월 1일
Again, you're choosing from an artificially finite set (63) of evenly spaced angles there. Also, this method will cluster points near the centre of the circle.
Azzi Abdelmalek
2013년 7월 31일
편집: Azzi Abdelmalek
2013년 7월 31일
x0=10; % x0 and y0 are center coordinates
y0=20;
r=1; % radius
angle=-pi:0.1:pi;
angl=angle(randi(numel(angle),15,1))
x=r*cos(angl)+x0
y=r*sin(angl)+y0
scatter(x,y)
xlim([-r r]+x0)
ylim([-r r]+y0)
axis square
댓글 수: 5
Azzi Abdelmalek
2013년 7월 31일
Richard, I think it's better to use randperm, with rand or randi there is a risk to have repetition
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!