How to add changing member colors indicating the changing forces within the various members to this animation
    6 views (last 30 days)
  
       Show older comments
    
Anyone know how to add code that basically changes the colour of each member according to which is in compression and tension. so red vs blue? 
function lorry =Lorry_plot
figure
view(3)
grid on
axis ('equal');
% lorry
vertices_lorry = [0 1 0.5 ; 4 1 0.5; 6.5 1 0.5; 6.5 1 1.2; 6 1 1.3;...
    5 1 1.8; 4 1 1.8; 4 1 2; 0 1 2; ... % postive y of lorry
    0 -1 0.5; 4 -1 0.5; 6.5 -1 0.5; 6.5 -1 1.2; 6 -1 1.3;...
    5 -1 1.8; 4 -1 1.8; 4 -1 2; 0 -1 2]; % negative y of lorry
faces_lorry_cargo = [10 1 9 18; 1 2 8 9; 8 9 18 17; 10 11 17 18;...
    7 8 17 16; 1 2 11 10];
faces_lorry_driver = [7 6 15 16 16 16; 5 6 15 14 14 14; 5 4 13 14 14 14;...
    3 4 13 12 12 12; 2 3 4 5 6 7; 11 12 13 14 15 16; 2 3 12 11 11 11];
lorry(1)=patch('Faces',faces_lorry_cargo,'Vertices',vertices_lorry,'FaceColor',...
    [1 1 0],'EdgeColor','k'); 
lorry(2)=patch('Faces',faces_lorry_driver,'Vertices',vertices_lorry,'FaceColor',...
    [0.8 0.8 0.8],'EdgeColor','k');
% wheels
t = linspace(pi,2*pi,8)';
[a,b] = pol2cart(t,0.5); % create data for circle
v0 = a*0;
X = [v0 a a v0];
Z = [v0 b b v0];
Y = [v0-1 v0-1 v0+1 v0+1]*0.15;  
hold on
lorry(3)=surf(X+1,Y+.85,Z+.5,'facecolor',[0 0 0]); % draw wheel rear left
lorry(4)=surf(X+1,Y-.85,Z+.5,'facecolor',[0 0 0]); % draw wheel rear right
lorry(5)=surf(X+3.97,Y+.85,Z+.5,'facecolor',[0 0 0]); % draw wheel front left
lorry(6)=surf(X+3.97,Y-.85,Z+.5,'facecolor',[0 0 0]); % draw wheel front right
hold off
% truss
vertices_truss = [0 2.25 0; 4.5 2.25 0; 9 2.25 0; 13.5 2.25 0; 18 2.25 0; 22.5 2.25 0; 27 2.25 0;...
    22.5 2.25 4.5; 18 2.25 4.5; 13.5 2.25 4.5; 9 2.25 4.5; 4.5 2.25 4.5;... % pink truss positive y
    0 -2.25 0; 4.5 -2.25 0; 9 -2.25 0; 13.5 -2.25 0; 18 -2.25 0; 22.5 -2.25 0; 27 -2.25 0;...
    22.5 -2.25 4.5; 18 -2.25 4.5; 13.5 -2.25 4.5; 9 -2.25 4.5; 4.5 -3.25 4.5]; % blue truss negative y
faces_truss = [1 2;2 3;3 4;4 5;5 6;6 7;7 8;8 9;9 10;10 11;11 12;12 1;12 2;12 3;...
    11 3;11 4;10 4;9 4;9 5;8 5;8 6;... %pink side
    13 14;14 15;15 16;16 17;17 18;18 19;19 20;20 21;21 22;22 23;23 24;...
    24 13;24 14;24 15;23 15;23 16;22 16;21 16;21 17;20 17;20 18;... %blue side
    1 13;2 14;3 15;4 16;5 17;6 18;7 19;8 20;9 21;10 22;11 23;12 24]; %transverse
patch('Faces',faces_truss,'Vertices',vertices_truss,'FaceAlpha',0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                                        %CODE TO DRIVE STARTS HERE%
% What is the final position of the front
% of the lorry along the x-axis?
maxX = 30;
% How far should the lorry travel on each frame/loop?
% For faster velocity, use higher value. 
stepSize = 0.05;
% Advance the lorry in steps of "stepSize" until
% the front of the lorry reaches "maxX". 
arrived = false;
while ~arrived
    lorry(1).Vertices(:,1) = lorry(1).Vertices(:,1) + stepSize;
    lorry(2).Vertices(:,1) = lorry(2).Vertices(:,1) + stepSize;
    lorry(3).XData = lorry(3).XData + stepSize;
    lorry(4).XData = lorry(4).XData + stepSize;
    lorry(5).XData = lorry(5).XData + stepSize;
    lorry(6).XData = lorry(6).XData + stepSize;
    drawnow()
    % use pause() to slow the velocity
    pause(0) 
    % Determine if the next step would overshoot target
    arrived = max(lorry(2).Vertices(:,1)) + stepSize > maxX;
end
end 
1 Comment
  Vashist Hegde
    
 on 22 Mar 2021
				Hi.
Can you please elaborate on what you meant by each member and where exactly you want to check for compression or tension?
Thanks.
Answers (0)
See Also
Categories
				Find more on Structural Analysis 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!
