User input changes circle radius and velocity

I want to make this so that when a user inputs a new radius, the circle changes accordingly, but I'm not sure how to go about it.
v=input('Please provide a particle velocity: \n');
r=input('Please provide a radius: \n');
x0 = 0;
y = 3;
for time=-7:0
x = x0(1,:) + v*time;
plot(x, y,'ro'); % particle moving along the x axis
axis([-3 3 -7 3])
drawnow();
pause(.5)
end
t = linspace(0,2*pi);
x = cos(t);
y = sin(t);
plot(3*x,3*y) % current plot circle - radius 10
axis equal
hold on
for t0 = t
h = plot(3*sin(t0),3*cos(t0),'or'); % particle moving around the circle
pause(0.3)
delete(h)
end
hold off

Risposte (2)

You are using the radius while calculating the coordinates of circle.
v=input('Please provide a particle velocity: \n');
r=input('Please provide a radius: \n');
x0 = 0;
y = 3;
for time=-7:0
x = x0(1,:) + v*time;
plot(x, y,'ro'); % particle moving along the x axis
axis([-3 3 -7 3])
drawnow();
pause(.5)
end
t = linspace(0,2*pi);
x = r*cos(t); % use the radius here
y = r*sin(t); % use the radius here
plot(x,y) % current plot circle - radius 10
axis equal
hold on
for t0 = t
h = plot(3*sin(t0),3*cos(t0),'or'); % particle moving around the circle
pause(0.3)
delete(h)
end
hold off
v=10;%input('Please provide a particle velocity: \n');
r=5; %input('Please provide a radius: \n'); e.g. radius here
x0 = -2; % offset
y0 = 3; % offset
t = linspace(0,2*pi);
x = x0 + r*cos(t); % use the radius here with an offset
y = y0 + r*sin(t); % use the radius here with an offset
plot(x,y) % current plot circle
x = r*cos(t); % use the radius here without an offset
y = r*sin(t); % use the radius here without an offset
hold on
plot(x,y,'r')
you can also try using an offset distance for centre to plot

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Prodotti

Release

R2021b

Richiesto:

il 26 Mar 2022

Risposto:

il 26 Mar 2022

Community Treasure Hunt

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

Start Hunting!

Translated by