Matlab Code

Drawing our Triangles

Credit: Tony Kanaan

Sample Code for Project1 Parts 1-3:

function out = MatlabDraw(theta)
%Knowns
L1 = 3;
L2 = 2*(2^.5);
L3 = 2*(2^.5);

gamma = pi/2;

p1 = 5^.5;
p2 = 5^.5;
p3 = 5^.5;

x1 = 4;
x2 = 0;
y2 = 4;

A2 = L3*cos(theta) - x1;
B2 = L3*sin(theta);
A3 = L2*cos(theta + gamma) - x2;
B3 = L2*sin(theta + gamma) - y2;

N1 = B3*(p2^2 - p1^2 - A2^2 - B2^2) - B2*(p3^2 - p1^2 - A3^2 - B3^2);
N2 = -A3*(p2^2 - p1^2 - A2^2-B2^2) + A2*(p3^2 - p1^2 - A3^2 - B3^2);
D = 2*(A2*B3 - B2*A3);
N1^2 + N2^2 - p1^2*D^2;

X = N1/D;
Y = N2/D;

%POINTS of Triangle
X1 = X;
Y1 = Y;

X2 = X+L2*cos(theta + gamma);
Y2 = Y+L2*sin(theta + gamma);

X3 = X+L3*cos(theta);
Y3 = Y+L3*sin(theta);


%Drawing Thriangle and Struts
plot([X1 X2 X3 X1],[Y1 Y2 Y3 Y1],'r');
hold on
plot([0 x1 x2],[0 0 y2],'bo');
plot([0 X1],[0 Y1], 'b');
plot([x1 X3],[0 Y3], 'r');
plot([x2 X2],[y2 Y2], 'g');
hold off
end

HOME