フィルターのクリア

User input changes circle radius and velocity

1 回表示 (過去 30 日間)
Olivia Rose
Olivia Rose 2022 年 3 月 26 日
回答済み: VBBV 2022 年 3 月 26 日
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

回答 (2 件)

KSSV
KSSV 2022 年 3 月 26 日
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 2022 年 3 月 26 日
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

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by