Line approximation algorithm.