Generating cicle instances around circumference

Hello,
for my work I need to generate instances (set of cooirdinaces xy) that have one point in the circle center and random set around (not necessarily on) circumference - like in the picture attached
Number off point should be parametr - so one can generata how many points is needed
I am trying to writte function to generate this points - but dont know how

 采纳的回答

th = linspace(0,2*pi)' ;
R = 1. ; % main circle radius
C = [0. 0.] ; % main circle center
x1 = C(1)+R*cos(th) ; y1 = C(2)+R*sin(th) ;
%% concetric circles
r1 = 0.75 ; r2 = 1.25 ;
x2 = C(1)+r1*cos(th) ; y2 = C(2)+r1*sin(th) ;
x3 = C(1)+r2*cos(th) ; y3 = C(2)+r2*sin(th) ;
%
a = max(x3);
b = min(x3);
x = (b-a).*rand(1000,1) + a;
y = (b-a).*rand(1000,1) + a;
%
% Remove poinsts out side r2 circle
idx = inpolygon(x, y,x3, y3) ;
x(~idx) = [] ; y(~idx) = [] ;
% Remove poinsts out side r1 circle
idx = inpolygon(x, y,x2, y2) ;
x(idx) = [] ; y(idx) = [] ;
% points needed
N = 100 ; % 25,50
idx = randperm(length(x),N) ;
x = x(idx) ; y = y(idx) ;
plot(x1,y1,'r') ;
hold on
plot(x2,y2,'b') ;
plot(x3,y3,'g') ;
plot(x,y,'.r')

4 个评论

thank you very much but how Do i change numbers of point inside?
I need to set like generate 25points, 50 points, 100 points etc.
Edited the code. Simple you select your required number of points randomly from (x,y).
thank you very much sir, You helped me a lot

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Neuroimaging 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by