%
% tent.m
%
% setup and deform a simple tent (figure 2 in notes)
%
%  usage:   tent(theta,k,f)
%
%  where:   theta = 1x2 vector or fiber angles
%           k     = 1x2 vector fiber stiffnesses
%           f     = 1x2 vector of forces at apex
%
%  example:   tent([pi/4 3*pi/4],[2 1],[0 .5])
%

function tent(theta,k,f)

% assume one stake at (0,0) and the other at (2,0) and 
% find the coordinates of the apex (a1,a2) by solving
% tan(th1)*a1 = tan(th2)*a1-2*tan(th2)

a1 = 2*tan(theta(2))/(tan(theta(2))-tan(theta(1)));
a2 = a1*tan(theta(1));

% plot the undeformed tent

plot([0 a1],[0 a2])
hold on
plot([2 a1],[0 a2])

A = [cos(theta(1)) sin(theta(1))      % the adjacency matrix
     cos(theta(2)) sin(theta(2))];

K = diag(k);			% the elemental stiffness matrix

S = A'*K*A;			% the mother stiffness matrix

x = S\f';			% solve for the displacements

% plot the deformed tent

plot([0 a1+x(1)],[0 a2+x(2)],'--')
plot([2 a1+x(1)],[0 a2+x(2)],'--')
hold off

