function [x,y] = auto(BS,S)
% [x,y] = auto(BS,S) describes the geometry of the
% length cut of a car cabin

% Here are the coordinates of the vertices of the
% polygonal domain arranged counterclockwise.
% The last coordinate pair equals the first one.
  X=[25,22, 7,1,4,4,0,4,7,7,11,13,15,11.8,16,16,20,22,25];
  Y=[ 8,14,14,8,8,5,5,0,0,3, 3, 8, 8,   0, 0, 3, 3, 8, 8];

  n=length(X)-1;

  % Determine number of boundary sections
  if (nargin==0)
    x=n;
    return;
  end
  
  Sec=[[0:n-1]; [1:n]; ones(1,n); zeros(1,n)];
  
  if(nargin==1)
    % Boundary section selection
    x=Sec(:,BS);
    return;
  end

  if(nargin==2)
    [m,n]=size(S);
    x=zeros(size(S));
    y=zeros(size(S));
    for i=1:n
      for j=1:m
        seg = BS(j,i);  % boundary segment number
        t = S(j,i) - (seg-1);   % loc. seg. coordinate
        x(j,i) = X(seg)*(1-t) + X(seg+1)*(t);
        y(j,i) = Y(seg)*(1-t) + Y(seg+1)*(t);
      end    
    end
  end
