Define the centre points, then add them as appropriate to ‘v_x’ and ‘v_y’ and ‘c_x’ and ‘c_y’:
xcntr = 7;
ycntr = 5;
...
v_x = R * cos((0:6)*pi/3) + xcntr;
v_y = R * sin((0:6)*pi/3) + ycntr;
...
c_x = R-rand(1, 3*N)*2*R + xcntr;
c_y = R-rand(1, 3*N)*2*R + ycntr;
In context:
N = 400;
R = 10;
xcntr = 7;
ycntr = 5;
v_x = R * cos((0:6)*pi/3) + xcntr;
v_y = R * sin((0:6)*pi/3) + ycntr;
c_x = R-rand(1, 3*N)*2*R + xcntr;
c_y = R-rand(1, 3*N)*2*R + ycntr;
IN = inpolygon(c_x, c_y, v_x, v_y);
c_x = c_x(IN);
c_y = c_y(IN);
idx = randperm(length(c_x));
c_x = c_x(idx(1:N));
c_y = c_y(idx(1:N));
plot(c_x, c_y, 'r*');
hold on;
plot(v_x,v_y);
hold off
axis equal
axis([-1 1 -1 1]*20)
Best Answer