function y = bht_link2(t,der,varargin)
% BHT_LINK2
%
% Boundary describing functions
%
% Syntax
%
% y = BHT_LINK2(t,der,settings)
%
% Description
%
% Thies function defines a boundary as a parameterized line over
% [0,2*pi[. The input variable t (the parameter) must be a vector with
% all of its elements within [0,2*pi[. The function returns, depending
% on the flag der:
%
% * der = 0: the coordinates of the points corresponding to the
% parameters t.
% * der = 1: the coordinates of the tangent vectors (the
% firsts derivatives of the parameterization).
% * der = 2: the second derivatives of the parameterization.
%
% The inpute variable settings is a row vector of eight elements.
% It is used to set the boundary's shape.
%
% See also BHT_BOUNDARY_CHECK
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% BIOHYDRODYNAMICS MATLAB TOOLBOX %
% %
% A. MUNNIER and B. PINCON %
% %
% alexandre.munnier@iecn.u-nancy.fr bruno.pincon@iecn.u-nancy.fr %
% http://www.iecn.u-nancy.fr/~munnier http://www.iecn.u-nancy.fr/~pincon %
% %
% %
% INSTITUT ELIE CARTAN, NANCY 1 %
% http://www.iecn.u-nancy.fr/ %
% %
% INRIA Lorraine, Projet CORIDA %
% http://www.iecn.u-nancy.fr/~corida/ %
% %
% %
% %
% %
% August 15th 2008 %
% %
% GNU GPL v3 licence %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%##########################################################################
% Reading settings
if isempty(varargin)
error('Boundary''s parameters (row vector of eigth elements) are missing.')
else
parameters = varargin{1};
end
if length(parameters)~=8
error('Boundary''s parameter vector must have eight elements');
end
%==========================================================================
% boundary's settings
a = parameters(1:4);
b = parameters(5:8);
%==========================================================================
n = length(t); % number of points
t = reshape(t,1,n);
%==============================
y = zeros(2,n);
%==========================================================================
if der == 0
y(1,:) = (a(1)/6+a(2)/3+a(3)/3+a(4)/6)...
+3/pi^2*(a(1)+a(2)-a(3)-a(4))*cos(t)...
+9/4/pi^2*(a(1)-a(2)-a(3)+a(4))*cos(2*t)...
+4/3/pi^2*(a(1)-2*a(2)+2*a(3)-a(4))*cos(3*t)...
+9/16/pi^2*(a(1)-a(2)-a(3)+a(4))*cos(4*t)...
+3/25/pi^2*(a(1)+a(2)-a(3)-a(4))*cos(5*t);
y(2,:) = sum(b)/6 ...
+3/2/pi^2*(b(1)-b(2)-b(3)+b(4))*cos(t)...
-9/8/pi^2*sum(b)*cos(2*t)...
-4/3/pi^2*(b(1)-b(2)-b(3)+b(4))*cos(3*t)...
-9/32/pi^2*sum(b)*cos(4*t)...
+3/50/pi^2*(b(1)-b(2)-b(3)+b(4))*cos(5*t)...
+3*sqrt(3)/2/pi^2*(b(1)+b(2)-b(3)-b(4))*sin(t)...
+9*sqrt(3)/8/pi^2*(b(1)-b(2)+b(3)-b(4))*sin(2*t)...
-9*sqrt(3)/32/pi^2*(b(1)-b(2)+b(3)-b(4))*sin(4*t)...
-3*sqrt(3)/50/pi^2*(b(1)+b(2)-b(3)-b(4))*sin(5*t);
elseif der == 1
y(1,:) = ...
-3/pi^2*(a(1)+a(2)-a(3)-a(4))*sin(t)...
-2*9/4/pi^2*(a(1)-a(2)-a(3)+a(4))*sin(2*t)...
-3*4/3/pi^2*(a(1)-2*a(2)+2*a(3)-a(4))*sin(3*t)...
-4*9/16/pi^2*(a(1)-a(2)-a(3)+a(4))*sin(4*t)...
-5*3/25/pi^2*(a(1)+a(2)-a(3)-a(4))*sin(5*t);
y(2,:) = ...
-3/2/pi^2*(b(1)-b(2)-b(3)+b(4))*sin(t)...
+2*9/8/pi^2*sum(b)*sin(2*t)...
+3*4/3/pi^2*(b(1)-b(2)-b(3)+b(4))*sin(3*t)...
+4*9/32/pi^2*sum(b)*sin(4*t)...
-5*3/50/pi^2*(b(1)-b(2)-b(3)+b(4))*sin(5*t)...
+3*sqrt(3)/2/pi^2*(b(1)+b(2)-b(3)-b(4))*cos(t)...
+2*9*sqrt(3)/8/pi^2*(b(1)-b(2)+b(3)-b(4))*cos(2*t)...
-4*9*sqrt(3)/32/pi^2*(b(1)-b(2)+b(3)-b(4))*cos(4*t)...
-5*3*sqrt(3)/50/pi^2*(b(1)+b(2)-b(3)-b(4))*cos(5*t);
elseif der == 2
y(1,:) = ...
-3/pi^2*(a(1)+a(2)-a(3)-a(4))*cos(t)...
-4*9/4/pi^2*(a(1)-a(2)-a(3)+a(4))*cos(2*t)...
-9*4/3/pi^2*(a(1)-2*a(2)+2*a(3)-a(4))*cos(3*t)...
-16*9/16/pi^2*(a(1)-a(2)-a(3)+a(4))*cos(4*t)...
-25*3/25/pi^2*(a(1)+a(2)-a(3)-a(4))*cos(5*t);
y(2,:) = ...
-3/2/pi^2*(b(1)-b(2)-b(3)+b(4))*cos(t)...
+4*9/8/pi^2*sum(b)*cos(2*t)...
+9*4/3/pi^2*(b(1)-b(2)-b(3)+b(4))*cos(3*t)...
+16*9/32/pi^2*sum(b)*cos(4*t)...
-25*3/50/pi^2*(b(1)-b(2)-b(3)+b(4))*cos(5*t)...
-3*sqrt(3)/2/pi^2*(b(1)+b(2)-b(3)-b(4))*sin(t)...
-4*9*sqrt(3)/8/pi^2*(b(1)-b(2)+b(3)-b(4))*sin(2*t)...
+16*9*sqrt(3)/32/pi^2*(b(1)-b(2)+b(3)-b(4))*sin(4*t)...
+25*3*sqrt(3)/50/pi^2*(b(1)+b(2)-b(3)-b(4))*sin(5*t);
end