MATLAB: Generating cicle instances around circumference

circumferencetsp

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

Best Answer

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')