



function result = shortestDist(x,y)

    TRI = delaunay(x,y);
    
    tempX = abs(x(TRI(:,1))-x(TRI(:,2)));
    tempY = abs(y(TRI(:,1))-y(TRI(:,2)));

    tempX1 = abs(x(TRI(:,1))-x(TRI(:,3)));
    tempY1 = abs(y(TRI(:,1))-y(TRI(:,3)));

    tempX2 = abs(x(TRI(:,2))-x(TRI(:,3)));
    tempY2 = abs(y(TRI(:,2))-y(TRI(:,3)));
    
    
    dist = sqrt(tempX.^2+tempY.^2);
    dist1 = sqrt(tempX1.^2+tempY1.^2);
    dist2 = sqrt(tempX2.^2+tempY2.^2);
    
    [A,ind] = min([dist,dist1,dist2],[],2);
    
    
    [~,ind1] = min(A);

switch ind(ind1)
    
    case 1
        
        result = [[x(TRI(ind1,1));x(TRI(ind1,2))],[y(TRI(ind1,1));y(TRI(ind1,2))]];
        
    case 2
        
        result = [[x(TRI(ind1,1));x(TRI(ind1,3))],[y(TRI(ind1,1));y(TRI(ind1,3))]];
    case 3
        
        result = [[x(TRI(ind1,2));x(TRI(ind1,3))],[y(TRI(ind1,2));y(TRI(ind1,3))]];
end
    

   plot(x,y,'.')
   hold on
   plot(result(:,1),result(:,2),'.r')
   
end
        
    