Date: Feb 11, 2013 11:23 AM
Author: Bruno Luong
Subject: Re: Merge line segments

% Try this:

function l = merge_lines(l1, l2)
l = [l1; l2];
p = (l*l');
d = diag(p);
d2 = bsxfun(@plus,d,d')-2*p;
[~, k] = max(d2(:));
l = l([mod(k-1,4)+1 ceil(k/4)],:);
end

% Bruno