% Project 1
function out = proj1_1(theta)
% The ouput should be N1^2+N2^2-p1^2*D^2 = 0
L1 = 2;
L2 = sqrt(2);
L3 = L2;
gamma = pi/2;
p1 = sqrt(5);
p2 = p1;
p3 = p1;
x1 = 4;
x2 = 0;
y2 = 4;
A2 = (L3*cos(theta))-x1;
A3 = L2*((cos(theta)*cos(gamma))-(sin(theta)*sin(gamma)))-x2;
B2 = L3*sin(theta);
B3 = L2*((cos(theta)*sin(gamma))+(sin(theta)*cos(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));
out = N1^2+N2^2-(p1^2*D^2);




%Generates Graph
x = -pi:pi/8:pi;
A2 = (L3*cos(x))-x1;
A3 = L2*((cos(x)*cos(gamma))-(sin(x)*sin(gamma)))-x2;
B2 = L3*sin(x);
B3 = L2*((cos(x)*sin(gamma))+(sin(x)*cos(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));
y = N1.^2+N2.^2-(p1^2*D.^2);
plot(x,y);
grid
