How to add changing member colors indicating the changing forces within the various members to this animation

2 ビュー (過去 30 日間)
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
  3 件のコメント
Rik
Rik 2021 年 4 月 15 日
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.

サインインしてコメントする。

回答 (1 件)

darova
darova 2021 年 3 月 20 日
編集済み: darova 2021 年 3 月 20 日
What about this?
clc,clear
n = 20;
r = linspace(1.5,5,20); % radius for curves animation
x = linspace(-1,1,n); % x coordinate
x(end+1) = nan; % make end point as NaN to remove last edge
y = sqrt(r(1)^2-x.^2);
cmap = flip(jet(n)); % create colormap
maxd = max(y)-min(y) % max difference height
cla
h = patch(x,-y+min(y),...
'edgecolor','interp',...
'linewidth',3);
ylim([-1 1]/2)
for i = 1:length(r)
y = sqrt(r(i)^2-x.^2);
ind = round((y-min(y))./maxd*(n-1)+1); % indices of colors
ind(end) = 1;
c = cmap(ind,:); % get colors
set(h,'xdata',x,'ydata',-y+min(y))
set(h,'facevertexcdata',c)
pause(0.5)
end
  9 件のコメント
latenfe
latenfe 2021 年 3 月 21 日
is there a way to make the members of my truss in the simulation blue/red
darova
darova 2021 年 3 月 21 日
Im sure its possible. Can you ask somethins specific?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructural Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by