MATLAB Answers

Animation of a translating and rotating rod

26 views (last 30 days)
SS on 9 Dec 2019
Edited: SS on 9 Dec 2019
Hi. I want to create an animation plot of a rod moving in 3D space. I have a structure array "data" which contains (X,Y,Z) centroid positions (data.x,data.y,data.z), the time step between the coordinates is 1/100 of a second. The length of the rod is 5 cms. The structure also contains the information of inplane projected angles (data.ang1 and data.ang2) in XY and ZX planes. These angles in combination with the rod length would be used in calculating the inital and final positions after each time step.
The rod is rotating during its motion, data.rot contains the rotation rate of the rod. I want the colorbar which represents the rotation rate.
Though, I do not have an exact figure of what, I want - I am attaching a figure I found on the internet which is close to my problem.
i=4; % particular rod I am interested in
for j=1:length(data(i).frames)
data(j).x=[data(i).x(j)+L/2*cos(data.ang1(j)) data(i).x(j)-L/2*cos(data(i).ang1(j))];
data(j).y=[data(i).y(j)+L/2*sin(data.ang1(j)) data(i).y(j)-L/2*sin(data(i).ang1(j))];
data(j).z=[data(i).z(j)+L/2*cos(data.ang2(j)) data(i).z(j)-L/2*cos(data(i).ang2(j))];
h=surface([data(j).x;data(j).x],[data(j).y;data(j).y],[data(j).z;data(j).z],[data(j).color data(j).color;data(j).color data(j).color],'facecol','no',...
I have used the above code and it is giving problems with surface command. Any help would be appreciated.


Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!