FEM-Course-Matlab/6.桁架结构matlab有限元编程/Truss2D/AxisForcePlot.m

63 lines
2.0 KiB
Matlab
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

%绘制桁架函数Scale为变形缩放系数(以下为绘制图像部分)
function AxisForce(ele,Load,Constr,x,y,U,LineWidth,LineStyle,Scale,AxialForce)
CoordScale=[max(x)-min(x),max(y)-min(y)];
k=1;
%计算变形后坐标
for i=1:length(x)
if Constr(k,1)==i%--约束节点坐标不变
k=k+1;
else%--非约束节点坐标加上缩放后的位移
x(i)=x(i)+Scale*U(2*i-1,1);y(i)=y(i)+Scale*U(2*i,1);
end
end
%绘制杆件
jet_color = colormap(jet(ceil(max(AxialForce)-min(AxialForce)+1)));%+1是为了避免索引为0
color_index = ceil(AxialForce+(1-min(AxialForce)));
for i=1:length(ele(:,1))
plot([x(ele(i,2)),x(ele(i,3))],[y(ele(i,2)),y(ele(i,3))],...
'color',jet_color(color_index(i),:),'LineWidth',LineWidth*ele(i,4)/max(ele(:,4)));
hold on
end
colorbar
caxis([min(AxialForce),max(AxialForce)]);
% figure
% for i=1:length(ele(:,1))
% plot([x(ele(i,2)),x(ele(i,3))],[y(ele(i,2)),y(ele(i,3))],...
% LineStyle,'LineWidth',LineWidth*ele(i,4)/max(ele(:,4)));
%
% hold on
% end
%绘制节点
for i=1:length(x)
x1=x(i);y1=y(i);
scatter(x1,y1,15,'k','filled')
end
%绘制载荷
maxLoad=abs(Load(1,2))%寻找绝对值最大的·载荷
for i=1:length(Load(:,1))
if(maxLoad<abs(Load(i,3)))
maxLoad=abs(Load(i,3))
end
end
for i=1:length(Load(:,1))%绘制载荷箭头
quiver(x(Load(i,1)),y(Load(i,1)),Load(i,2)/max(maxLoad),...
Load(i,3)/max(maxLoad),...
'LineWidth',1,'color','r','AutoScaleFactor',0.15*(CoordScale(1)+CoordScale(2)),...
'MaxHeadSize',0.01*(CoordScale(1)+CoordScale(2)));
end
%绘制约束--选用结构最大的坐标尺寸作为基准来绘制约束
for i=1:length(Constr(:,1))
plot([x(Constr(i,1)) x(Constr(i,1))-0.02*max(CoordScale) x(Constr(i,1))+...
0.02*max(CoordScale) x(Constr(i,1))],[y(Constr(i,1)) y(Constr(i,1))-...
0.02*max(CoordScale) y(Constr(i,1))-0.02*max(CoordScale) y(Constr(i,1))],...
'LineWidth',0.8,'color','r');
end
%绘制坐标轴
axis equal
axis([min(x)-0.1*CoordScale(1),max(x)+0.1*CoordScale(1),min(y)-...
0.1*CoordScale(2),max(y)+0.1*CoordScale(2)]...
) %限定图像的显示范围
hold off
end