function [ alpha  F ] = OptimumWingAngle( theta, V )
%This function computes the optimum wing angle relative to the spine, give
%the incoming water direction relative to the spine.
%Also computed and output is the force vector, component 1 is the force
%along the spine, and component 2 is the force normal to the spine.

%close all
%clear all
%V = 0.25;
%theta = 32;


[rho S Cp C ] = Constants();
C4 = C/4;

F = zeros(3,1);

%alpha_test = [-30:10];  %Deployed
alpha_test = -90:.1:90;

Fwing = HorzForce(alpha_test,theta);
[Fmax idx] = max(Fwing(1,:));


alpha = alpha_test(idx)+0;

F = HorzForce(alpha,theta);

qinf = .5*rho*V.^2;

F0 = S*qinf*C;
M0 = S*qinf*C*C;

F(1) = F0*F(1);
F(2) = F0*F(2);


aoa = alpha-theta;

[cl cd cm]=Coef0015(aoa*pi/180);

cl = 0.75*cl;  %Rough adjustment for finite span.

L = cl*F0;
D = cd*F0;
M = cm*M0;

F(3) = M+L*(Cp-C4).*cos(aoa*pi/180)+D*(Cp-C4).*sin(aoa*pi/180);


end



