perfect circles algorithm