% split the bike template into left-right two halves

TotalsketchAll = zeros(1, nbasis); 
for iSketch = 1:Totalsketch
    if My(iSketch) <= midY
        di = 1; 
    else
        di = 2;
    end
    TotalsketchAll(di) = TotalsketchAll(di)+1; 
    MmAll(di, TotalsketchAll(di)) = Mm(iSketch);
    Mm1All(di, TotalsketchAll(di)) = Mm1(iSketch);
    MxAll(di, TotalsketchAll(di)) = Mx(iSketch);
    MyAll(di, TotalsketchAll(di)) = My(iSketch);
    MiAll(di, TotalsketchAll(di)) = Mi(iSketch);
end

exten = h + sub*Lrange; 
for (di = 1 : nbasis)
 minX = min(MxAll(di, 1:TotalsketchAll(di)))-exten;
 maxX = max(MxAll(di, 1:TotalsketchAll(di)))+exten;
 cxAll(di) = round((minX+maxX)/2); 
 sxAll(di) = maxX-minX;
 MxAll(di, 1:TotalsketchAll(di)) = MxAll(di, 1:TotalsketchAll(di))-cxAll(di); 
 
 minY = min(MyAll(di, 1:TotalsketchAll(di)))-exten;
 maxY = max(MyAll(di, 1:TotalsketchAll(di)))+exten;
 cyAll(di) = round((minY+maxY)/2);
 syAll(di) = maxY-minY;
 MyAll(di, 1:TotalsketchAll(di)) = MyAll(di, 1:TotalsketchAll(di))-cyAll(di); 
end

xRange = 4; yRange = 20; 
cyAll(1) = cyAll(1) - yRange; cyAll(2) = cyAll(2) + yRange; 
FxAll = zeros(1, nbasis); FyAll = zeros(1, nbasis); 
midX = round((max(cxAll(1, :))+ min(cxAll(1, :)))/2.); 
midY = round((max(cyAll(1, :))+ min(cyAll(1, :)))/2.); 
FxAll = cxAll - midX; 
FyAll = cyAll - midY; 
