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 个评论
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
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.

请先登录,再进行评论。


Azzi Abdelmalek
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
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 CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by