필터 지우기
필터 지우기

How can I animate springs in MATLAB?

조회 수: 5 (최근 30일)
Srikar V.S
Srikar V.S 2023년 3월 29일
답변: Star Strider 2023년 3월 29일
I'm trying to animate a simple spring-mass system vibrating freely. I managed to animate a block vibrating according to the response of a free vibration using the method of continuos plots using a for loop. Now, i want to include the spring in the system so as to complete the movie. However, I'm having a hard time trying to do that, I'm a beginner in MATLAB, so I don't know much about the various functions available in it. I couldn't get the right source to help me out.

채택된 답변

Star Strider
Star Strider 2023년 3월 29일
One approach —
L = 1600; % Vector Lengths
t = linspace(0, 16*pi-(1/L), L); % Eight Cycles
r = 1; % Radius
x = r*cos(t); % X-Coordinate
y = r*sin(t); % Y-Coordinate
tz = linspace(0, t(end), fix(L/2)); % Length Governs Frequency Of Oscillation
zv = (1+sin(tz))*4; % Oscillation
figure
for k = 1:numel(z)
z = linspace(0, zv(k), L)+2; % Define Spring Length For This Cycle
plot3(x, y, z, 'LineWidth',2.5) % Draw Spring
axis([-1.5 1.5 -1.5 1.5 0 10]) % Fix Axis Limits
grid on % Draw Grid
drawnow % Animate
end
It does not show the animation here, however it does work.
Experiment with it to get the result you want. (I did my best to document it in the comments.) In the loop, the ‘z’ value controls the length for each iteration, using the ‘zv’ value, however ‘zv’ can be anything. It does not have to be the vector I used here to test the code, so in reality it will be related to something in your animation. I have drawn it vertically here, however by changing the order of the plot3 call arguments, you can put it in different orientations. You can also use the rotate function to put it in other orientations, if necessary.
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by