Inlier (current best model) Outlier (current best model) Current random pair Best-fit line

RANSAC Robust Line Fitting (2D)

Random Sample Consensus (RANSAC) is the workhorse robust-estimation algorithm behind homography and fundamental-matrix fitting, lane-line and horizon detection, and 2D feature-match filtering — anywhere a computer-vision pipeline must fit a model to data containing gross outliers that an ordinary least-squares fit cannot tolerate. This simulator scatters 2D points around a hidden true line, contaminates it with a controllable fraction of pure-noise outliers, and runs the real RANSAC loop live: sample two points, fit the exact line through them, count how many of all N points lie within a distance threshold, and keep whichever candidate line wins the largest consensus set. Because a line needs only two points to fix it (versus three for a plane), the math and the convergence behaviour differ from the 3D case even though the algorithm is identical — watch the best-fit line and its inlier set (green) converge onto the true line as iterations accumulate, tune outlier fraction, measurement noise and the inlier threshold to see how each degrades or helps convergence, and compare the live iteration count against the closed-form k = ⌈ln(1−P)/ln(1−w²)⌉ that predicts how many random trials are needed for 99% confidence at a given inlier ratio.