51 lines
1.5 KiB
Matlab
51 lines
1.5 KiB
Matlab
%绘制桁架函数,Scale为变形缩放系数(以下为绘制图像部分)
|
||
function RenderTruss(ele,Load,Constr,x,y,U,LineWidth,LineStyle,Scale)
|
||
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
|
||
%绘制杆件
|
||
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 |