MATLAB Answers

0

Circle plot and random point on circle

Asked by Eleni agou on 16 Sep 2018 at 11:47
Latest activity Commented on by Eleni agou on 16 Sep 2018 at 14:33

Hi,

I drawn a circle on matlab with parametric equations. I give the xcenter,ycenter,r(x1,y1,r1) and the s.S is the number of points which equidistant(have the same distance on circle). I drawn some points on circle and I want to draw 4 random points around. My code is:

t1 = 0:(pi/(5*s1)):2*pi; % s1 is the number of points I want 
x1unit = r1 * cos(t1) + x1; 
y1unit = r1 * sin(t1) + y1;
a1=x1unit(1:10:s1*10); %points around on circle
b1=y1unit(1:10:s1*10);
plot(x1unit, y1unit, 'b', x1, y1, 'ok');%circle 
plot(a1, b1, 'o');

I want random points on circle 3 ,4,or 5 or more on circle.But I couldn't to success it , yes. Could you help me?

Thanks in andvance,

  0 Comments

Sign in to comment.

1 Answer

Answer by Image Analyst
on 16 Sep 2018 at 12:55
Edited by Image Analyst
on 16 Sep 2018 at 13:49
 Accepted Answer

Try this:

% Plot a circle.
angles = linspace(0, 2*pi, 720); % 720 is the total number of points
radius = 20;
xCenter = 50;
yCenter = 40;
x = radius * cos(angles) + xCenter; 
y = radius * sin(angles) + yCenter;
% Plot circle.
plot(x, y, 'b-', 'LineWidth', 2);
% Plot center.
hold on;
plot(xCenter, yCenter, 'k+', 'LineWidth', 2, 'MarkerSize', 16);
grid on;
axis equal;
xlabel('X', 'FontSize', 16);
ylabel('Y', 'FontSize', 16);
% Now get random locations along the circle.
s1 = 5; % Number of random points to get.
randomIndexes = randperm(length(angles), s1)
xRandom = x(randomIndexes);
yRandom = y(randomIndexes);
plot(xRandom, yRandom, 'ro', 'LineWidth', 2, 'MarkerSize', 16);

  3 Comments

Eleni's "Answer" moved here since it's not an answer to the original post, but a reply to mine:

thank you,

but I want the new random points and the s1 points. In this way, I have only the new random points.

a1=x1unit(1:10:s1*10); %points around on circle

b1=y1unit(1:10:s1*10);

Here is the code with equals points on circle

720 is the total number of points. You can replace this by whatever you want. s1 is a scalar and is the number of points randomly selected from full set of 720 points. The "new random points" (all s1 of them) are all held in vectors xRandom and yRandom. I think you have everything you need, don't you?

yes!!

thank you for your time

Sign in to comment.