function geom = planarbend2D(geomparams)


%% PARAMETERS
%pre-bend straight length L1, post-bend straight length L2, bend radius and
% and angle R_B and theta_B, duct radius R_i
if ~exist('geomparams','var')
    geomparams.L1       = 2;
    geomparams.L2       = 2;
    geomparams.X_i      = 1;
    geomparams.R_B      = 5/8;
    geomparams.theta_B  = 8*1.6375/5;
end

L1      = geomparams.L1;
L2      = geomparams.L2;
X_i     = geomparams.X_i;
R_B     = geomparams.R_B;
theta_B = geomparams.theta_B;

geom.geomparams = geomparams;


%% SCALAR S-FUNCTIONS
    function kappa = ductcurvature(s)
        if s < L1
            kappa = 0;
        elseif s > L1 + R_B*abs(theta_B)
            kappa = 0;
        else
            kappa = 1/R_B;
        end
    end
geom.L      = L1 + R_B*abs(theta_B) + L2;
geom.X      = @(s) X_i;
geom.Xdash  = @(s) 0;
geom.Xpl    = @(s) 0.5*X_i;
geom.Xpldash= @(s) 0;
geom.Xmn    = @(s) -0.5*X_i;
geom.Xmndash= @(s) 0;
geom.kappa  = @(s) ductcurvature(s);
geom.theta0 = @(s) 0;
geom.qyvar  = true;
geom.qzvar  = false;


%% VECTOR S-FUNCTIONS
    function x = ductpathx(s,parity,cl)
        if s < L1
            x = cl*s;
        elseif s > L1 + R_B*abs(theta_B)
            x = cl*(L1 + cos(theta_B)*(s - L1 - R_B*abs(theta_B)))...
            + parity*sin(abs(theta_B));
        else
            x = cl*L1 + parity*sin((s - L1)/R_B);
        end
    end
    function y = ductpathy(s,parity,cl)
        if s < L1
            y = (1 - cl)*sign(theta_B);
        elseif s > L1 + R_B*abs(theta_B)
            y = cl*(R_B*sign(theta_B) + sin(theta_B)*(s - L1 ...
                - R_B*abs(theta_B)))...
                - parity*cos(theta_B)*sign(theta_B);
        else
            y = (cl*R_B - parity*cos((s - L1)/R_B))...
                *sign(theta_B);
        end
    end

geom.qx = @(s) ductpathx(s,R_B,1);
geom.qy = @(s) ductpathy(s,R_B,1);
geom.nx = @(s) ductpathx(s,-1,0);
geom.ny = @(s) ductpathy(s,-1,0);


%% GEOMETRY NAME
geom.name = 'planarbend2D';

end