How to create a time function and make a line rotate at a certain angular speed?
4 views (last 30 days)
Show older comments
Hello! I have a question regarding my code I am trying to make an animation of a four bar linkage but in the end I need to plot theta_2 vs time. Angular speed should be 1 rad/sec, but I'm having trouble trying to wrap my head around the concept of time in MATLAB. How could I make the line rotate at a certain angular speed and how would I plot a graph of theta vs time? Any insight would be appreciated! Thanks!
r2_length = 2;
theta_2 = 0:0.1:2*pi;
y_r2 = r2_length * sin(theta_2);
x_r2 = r2_length * cos(theta_2);
origin = [0,0];
for i = 1:length(theta_2)
r2 = line([origin(1) x_r2(i)], [origin(2) y_r2(i)],'linewidth', 2);
hold on
axis([-10 10, -10 10]);
grid on
pause(0.001);
if i ~= length(theta_2)
clf
end
end
0 Comments
Answers (1)
Alan Stevens
on 26 May 2023
Do you mean something like this?
r2_length = 2;
tend = 10; % s
dt = 0.1;
t = 0:dt:tend;
omega = 1; % rad/s
theta = omega*t;
y_r2 = r2_length * sin(theta);
x_r2 = r2_length * cos(theta);
origin = [0,0];
for i = 1:length(theta)
r2 = line([origin(1) x_r2(i)], [origin(2) y_r2(i)],'linewidth', 2);
hold on
axis([-5 5, -5 5]);
grid on
pause(0.001);
if i ~= length(theta)
clf
end
end
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!