Generate random coordinates around a circle

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

Cedric
Cedric 2013년 7월 31일
What have you tried so far?
John
John 2013년 7월 31일
I can generate the random coordinates within R (below) but I don't know how to change them so that they are distributed around coordinate, say [20 30]
R.*rand(15,2)
Richard Brown
Richard Brown 2013년 7월 31일
Hint: polar coordinates
John
John 2013년 7월 31일
Unfortunately, I rarely use Matlab, I have no clue how to do it even with the polar coordinates hint

댓글을 달려면 로그인하십시오.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 31일
편집: Azzi Abdelmalek 2013년 8월 1일

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
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.
John
John 2013년 8월 1일
The link http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_set_of_random_locations_within_a_circle.3F provided by Richard Brown worked, Thanks you all for your help

댓글을 달려면 로그인하십시오.

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 31일
편집: Azzi Abdelmalek 2013년 7월 31일

0 개 추천

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

I presume you mean
angl = 2*pi*rand(1, 15)
John
John 2013년 7월 31일
This seems to work but the coordinates seem to be distributed along the circle circumference. Is there a way to distribute them all over the circle? Thanks
Richard Brown
Richard Brown 2013년 7월 31일
편집: Richard Brown 2013년 7월 31일
I seem to recall Roger Stafford answering this very question maybe yesterday? Could be worth trawling through recent questions to have a look. edit Actually, it was a while ago, but it got updated yesterday:
Do you mean inside the circle?
Richard, I think it's better to use randperm, with rand or randi there is a risk to have repetition

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2013년 7월 31일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by