B = bernsteinMatrix(n1,t);
s(t) = int(norm(diff(bezierCurve)),0,t);
snum = linspace(0,s(1),T);
tnum(i) = vpasolve(snum(i)==s(t),t);
px = double(subs(bezierCurve(:,1),t,tnum)).';
pz = double(subs(bezierCurve(:,2),t,tnum)).';
normalToCurve = diff(bezierCurve)*[0 1;-1 0];
normalToCurve = normalToCurve/norm(normalToCurve);
newNormalToCurve = [double(subs(normalToCurve(1),t,tnum))' double(subs(normalToCurve(2),t,tnum))'];
newNormalToCurvex = newNormalToCurve(:,1);
newNormalToCurvez = newNormalToCurve(:,2);
plot3(px,py,pz,'b-o',"MarkerSize",4)
S = double(s((i-1)/(T-1)));
d = R*(1-S/double(s(1)))+(H/2)*S/double(s(1));
pxnew1 = px+newNormalToCurvex.*delta;
pznew1 = pz+newNormalToCurvez.*delta;
S = double(s((i-1)/(T-1)));
rhilfe = (h/2)*S/double(s(1));
plot3(pxnew1,pynew1,pznew1,'r-o','MarkerSize',4)
pxnew2 = px+newNormalToCurvex.*delta;
pznew2 = pz+newNormalToCurvez.*delta;
plot3(pxnew2,pynew1,pznew2,'r-o','MarkerSize',4)
S = double(s((i-1)/(T-1)));
chilfe = R*(1-S/double(s(1)))+(h/2)*S/double(s(1));
S = double(s((i-1)/(T-1)));
lhilfe = H/2*S/double(s(1));
pxnew3 = px+newNormalToCurvex.*l*(-1)^i;
pznew3 = pz+newNormalToCurvez.*l*(-1)^i;
plot3(pxnew3,pynew3,pznew3,'k-o','MarkerSize',4)
plot3(pxnew3,pynew3,pznew3,'k-o','MarkerSize',4)
pxnew3a = px-newNormalToCurvex.*l;
pxnew3b = px+newNormalToCurvex.*l;
pznew3a = pz-newNormalToCurvez.*l;
pznew3b = pz+newNormalToCurvez.*l;
S = double(s((i-1)/(T-1)));
jhilfe = Rnewx*(1-S/double(s(1)))+(H/2)*S/double(s(1));
S = double(s((i-1)/(T-1)));
ehilfe = Rnewy*(1-S/double(s(1)))+(h/2)*S/double(s(1));
pxnew4 = px+newNormalToCurvex.*j;
pznew4 = pz+newNormalToCurvez.*j;
pynew4 = ones(T,1).*e*(-1)^i;
plot3(pxnew4,pynew4,pznew4,'m-o',"MarkerSize",4)
pxnew5 = px-newNormalToCurvex.*j;
pznew5 = pz-newNormalToCurvez.*j;
pynew5 = ones(T,1).*e*(-1)^i;
plot3(pxnew5,pynew5,pznew5,'g-o',"MarkerSize",4)
pxgesamt = [px;pxnew1; pxnew1; pxnew2; pxnew2; pxnew3a;pxnew3b;pxnew3a;pxnew3b;pxnew4; pxnew4; pxnew5; pxnew5];
pygesamt = [py;pynew1a;pynew1b;pynew2a;pynew2b;pynew3a;pynew3a;pynew3b;pynew3b;pynew4a;pynew4b;pynew5a;pynew5b];
pzgesamt = [pz;pznew1; pznew1; pznew2; pznew2; pznew3a;pznew3b;pznew3a;pznew3b;pznew4; pznew4; pznew5; pznew5];
pgesamt = [pxgesamt pygesamt pzgesamt];
arclen = arclength(px,pz);
S = linspace(0,arclen,T);
p2y1 = linspace(0,h/2,T);
z2t = R*(1-S(i)/arclen)+(H/2)*S(i)/arclen;
c2hilfe = R*(1-S(i)/arclen)+h/2*(S(i)/arclen);
p2z3 = linspace(0,H/2,T);
j2hilfe = Rnew*(1-S(i)/arclen)+(H/2)*S(i)/arclen;
e2hilfe = Rnew*(1-S(i)/arclen)+(h/2)*S(i)/arclen;
pyt = [p2y1(i); p2y4(i); p2y3(i); p2y3(i); p2y4(i); p2y2(i); p2y2b(i); p2y4b(i);
p2y3b(i); p2y3b(i); p2y4b(i); p2y1b(i); p2y1(i)];
pzt = [p2z1(i); p2z4(i); p2z3(i); p2z3b(i); p2z5(i); p2z2(i); p2z2(i); p2z5(i);
p2z3b(i); p2z3(i); p2z4(i); p2z1(i); p2z1(i)];
plot(pyt,pzt,'o',"MarkerSize",3,"MarkerEdgeColor",'k')
pyt = [p2y1(i);p2y1b(i)];
plot(pyt,pzt,'k-',"MarkerSize",3,"MarkerEdgeColor",'k')
pyt = [p2y3(i); p2y3(i)];
pzt = [p2z3(i); p2z3b(i)];
plot(pyt,pzt,'k-',"MarkerSize",3,"MarkerEdgeColor",'k')
pyt = [p2y2(i); p2y2b(i)];
pzt = [p2z2(i); p2z2(i)];
plot(pyt,pzt,'k-',"MarkerSize",3,"MarkerEdgeColor",'k')
pyt = [p2y3b(i); p2y3b(i)];
pzt = [p2z3b(i); p2z3(i)];
plot(pyt,pzt,'k-',"MarkerSize",3,"MarkerEdgeColor",'k')
radius = R*(1-S(i)/arclen);
MPxhilfe = h/2*S(i)/arclen;
MPyhilfe = H/2*S(i)/arclen;
xc = MP(i,1)+rad(i)*cosd(deg);
yc = MP(i,2)+rad(i)*sind(deg);
xc = MP(i,1)+rad(i)*cosd(deg);
yc = -MP(i,2)-rad(i)*sind(deg);
xc = -MP(i,1)-rad(i)*cosd(deg);
yc = -MP(i,2)-rad(i)*sind(deg);
xc = -MP(i,1)-rad(i)*cosd(deg);
yc = MP(i,2)+rad(i)*sind(deg);
function [arclen,seglen] = arclength(px,py,varargin)
error('ARCLENGTH:insufficientarguments', ...
'at least px and py must be supplied')
if ~isvector(px) || ~isvector(py) || (length(py) ~= n)
error('ARCLENGTH:improperpxorpy', ...
'px and py must be vectors of the same length')
error('ARCLENGTH:improperpxorpy', ...
'px and py must be vectors of length at least 2')
for i = 1:numel(varargin)
validmethods = {'linear' 'pchip' 'spline'};
ind = strmatch(lower(arg),validmethods);
if isempty(ind) || (length(ind) > 1)
error('ARCLENGTH:invalidmethod', ...
'Invalid method indicated. Only ''linear'',''pchip'',''spline'' allowed.')
method = validmethods{ind};
error('ARCLENGTH:inconsistentpz', ...
'pz was supplied, but is inconsistent in size with px and py')
seglen = sqrt(sum(diff(data,[],1).^2,2));
if strcmpi(method,'linear')
diffarray = [3 0 0;0 2 0;0 0 1;0 0 0];
spl{i} = pchip([0;cumsum(chordlen)],data(:,i));
spl{i} = spline([0;cumsum(chordlen)],data(:,i));
nc = numel(spl{i}.coefs);
spl{i}.coefs = [zeros(1,4-nc),spl{i}.coefs];
xp.coefs = xp.coefs*diffarray;
polyarray(j,:) = spld{j}.coefs(i,:);
seglen(i) = quadgk(@(t) segkernel(t),0,chordlen(i));
function val = segkernel(t)
val = val + polyval(polyarray(k,:),t).^2;