How to create a time function and make a line rotate at a certain angular speed?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Alan Stevens
2023년 5월 26일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!