% Mika Juntunen / 19.1.2007
%
% This is a simple function that plots a truss to current
% figure.
%
% function plot_truss(joints,bars)
%
% input:
% joints - 2xN matrix containing the location of joints
% bars - 2xN matrix containing the bars i.e. one column is the
%        joints that are connected
%

function plot_truss(joints,bars)

% first plot circles to mark joints
plot(joints(1,:),joints(2,:),'ko','MarkerSize',8,'MarkerFaceColor','k')

% plot lines to connect joints
line([joints(1,bars(1,:));joints(1,bars(2,:))],...
     [joints(2,bars(1,:));joints(2,bars(2,:))],...
     'Color',[0 0 1],'LineWidth',2)

% set axis limits so that the truss is better visible
xmin = min(joints(1,:));
xmax = max(joints(1,:));
ymin = min(joints(2,:));
ymax = max(joints(2,:));
xdev = 0.05*max(abs(joints(1,:)));
ydev = 0.05*max(abs(joints(2,:)));

axis([xmin-xdev xmax+xdev ymin-ydev ymax+ydev])


