function RANSAC_line

a = 1;
b = 1;

nPoints = 100;

x = rand(nPoints,1)-0.5;
y = a*x + b + 0.2*randn(nPoints,1);

figure(1)
clf;
plot(x,y, 'b.');
axis equal
grid on

nRansacIter = 500;
threshold = 0.1;
max_nInliers = 0;
for i = 1 : nRansacIter
    r = randperm(nPoints);
    s1 = [x(r(1)); y(r(1)); 1];
    s2 = [x(r(2)); y(r(2)); 1];
    l = GetLineFromTwoPoints(s1, s2);
    
    nInliers = 0;
    for j = 1 : nPoints
        e = abs(l' * [x(j); y(j); 1])/norm(l(1:2));
        if (e < threshold)
            nInliers = nInliers + 1;
        end
    end
    
    if (nInliers > max_nInliers)
        max_nInliers = nInliers;
        L = l;
    end
end
max_nInliers

hold on
x_min = -1;
y_min = -(L(1)*x_min+L(3))/L(2);
x_max = 1;
y_max = -(L(1)*x_max+L(3))/L(2);
plot([x_min x_max], [y_min y_max], 'r-');