User input changes circle radius and velocity

1 visualización (últimos 30 días)
Olivia Rose
Olivia Rose el 26 de Mzo. de 2022
Respondida: VBBV el 26 de Mzo. de 2022
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

Respuestas (2)

KSSV
KSSV el 26 de Mzo. de 2022
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

VBBV
VBBV el 26 de Mzo. de 2022
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

Categorías

Más información sobre Animation en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by