function geom = planarbend3D(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       = 0/2.4;
    geomparams.L2       = 0/2.4;
    geomparams.R_i      = 0.5;
    geomparams.R_B      = 1.25;
    geomparams.theta_B  = -pi/2;
end

L1      = geomparams.L1;
L2      = geomparams.L2;
R_i     = geomparams.R_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.R      = @(s) R_i;
geom.Rdash  = @(s) 0;
geom.kappa  = @(s) ductcurvature(s);
geom.tau    = @(s) 0;
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.qz = @(s) 0;
geom.nx = @(s) ductpathx(s,-1,0);
geom.ny = @(s) ductpathy(s,-1,0);
geom.nz = @(s) 0;
geom.bx = @(s) 0;
geom.by = @(s) 0;
geom.bz = @(s) sign(theta_B);


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

end