Generate random coordinates around a circle

1 Ansicht (letzte 30 Tage)
John
John am 31 Jul. 2013
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 Kommentare
Richard Brown
Richard Brown am 31 Jul. 2013
Hint: polar coordinates
John
John am 31 Jul. 2013
Unfortunately, I rarely use Matlab, I have no clue how to do it even with the polar coordinates hint

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 31 Jul. 2013
Bearbeitet: Azzi Abdelmalek am 1 Aug. 2013
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 Kommentare
Richard Brown
Richard Brown am 1 Aug. 2013
Bearbeitet: Richard Brown am 1 Aug. 2013
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 am 1 Aug. 2013
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

Melden Sie sich an, um zu kommentieren.


Azzi Abdelmalek
Azzi Abdelmalek am 31 Jul. 2013
Bearbeitet: Azzi Abdelmalek am 31 Jul. 2013
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 31 Jul. 2013
Do you mean inside the circle?
Azzi Abdelmalek
Azzi Abdelmalek am 31 Jul. 2013
Richard, I think it's better to use randperm, with rand or randi there is a risk to have repetition

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by