  function  [xStar,yStar,ThetaStar] = Sideline(a,b,d,w)
% a, b, c, d are positive real numbers with  the property that 
% P1 = (-d,-w/2) and P2 = (-d,w/2) are inside the ellipse (x/a)^2 + (y/b)^2 = 1.
% Q = (xStar,yStar) is a point on the ellipse  with the property  that
% angle P1-Q-P2 is maximized where P1 = (-d,-w/2) and P2 = (-d,w/2). ThetaStar is the 
% maximum angle in degrees. 

[xStar,ThetaStar] = fminbnd(@(x) Angle(x,a,b,d,w) ,-d,a);
yStar = -b*sqrt(1-(xStar/a)^2);
ThetaStar = 180*(ThetaStar/pi);


function theta = Angle(x,a,b,d,w)       
y = -b*sqrt(1-(x/a)^2);
theta = -(atan2(w/2-y,x+d)-atan2(-w/2-y,x+d));

% Grading:

% 3 points: correct use of fminbnd
% 2 points: correct math and output

% -1 for incorrect bounds on the minimization
% -1 for returning theta in radians