Algebraic solution for fitting a circle