Code covered by the BSD License  

Highlights from
Biohydrodynamics Toolbox

image thumbnail
from Biohydrodynamics Toolbox by Alexandre Munnier
Tool to simulate easily the motion of moving solids or swimming robots in a potential fluid flow.

bht_round_rectangle(t,der,varargin)
function y = bht_round_rectangle(t,der,varargin)
% BHT_ROUND_RECTANGLE
% 
% Define a rectangle-shaped boundary.
% 
% Syntax
% 
%     y = BHT_ROUND_RECTANGLE(t,der,settings)
% 
% Description
% 
%     This function defines a rectangle-shaped boundary as a parameterized
%     closed line over [0,2*pi[. The input variable t (the parameter) is 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(k). 
%     * der = 1: the coordinates of the tangent vectors
%       (the first derivatives of the parameterization). 
%     * der = 2: the second derivatives of the parameterization.
% 
%     The input variable settings is a row vector with six elements: 
%     *  the rectangle is centered at the point of coordinates settings(3:4). 
%     *  Its width is 2*settings(1) and its height is 2*settings(2).
%     *  Since boundaries have to be twice continuously differentiable lines within
%        BhT, rectangle's corners are smoothed. Thus, settings(5) has to be
%        within ]0,1] and is the smoothing parameter. 
%     *  At last, settings(6) is a flag (-1 or 1) for the orientation of the 
%        boundary: 1 means that the boundary has counterclockwise orientation
%        and -1 clockwise orientation.
% 
% 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 at least six elements) are missing.')
else
parameters = varargin{1};
end

if length(parameters) ~= 6
    error('Boundary''s parameter vector must have at least six elements');
end

% =========================================================================
% smoothing parameter
epsilon = parameters(5);
if epsilon <=0 || epsilon > 1
    error('Fifth element of parameter vector is the smoothing parameter (must be between 0 and 1)') 
end
epsilon = epsilon*pi/4;
% =========================================================================
% rectangle's size
L = parameters(3);
l = parameters(4);
% center
center = reshape(parameters(1:2),2,1);
% =========================================================================
orient = parameters(6); % -1 for ext and 1 for int
if orient^2 ~= 1
    error('Last element of parameter vector must be 1 (fluid outside) or -1 (fluid inside)')
end
% =========================================================================
n = length(t);
t = reshape(t,1,n); % assure la forme ligne  

[x1,dx1,ddx1] = bht_step1(t,pi/4+epsilon,L);
x1 = x1 + center (1)*ones(1,n);
[x2,dx2,ddx2] = bht_step2(t,pi/4+epsilon,-orient*l);
x2 = x2 + center(2)*ones(1,n);

if der == 0
  y = [x1; x2];
elseif der == 1
  y = [dx1; dx2];
elseif der == 2
  y = [ddx1; ddx2];
else
  error('der doit etre 0, 1 ou 2')
end

Contact us at files@mathworks.com