import warnings


def fit_circle_3pts(xs, ys):
    """Fit the center of a circle using algebraic approximation with only 3 points.

    Parameters
    ----------
    xs, ys: {3, N, ...} array_like
        The 3 points to fit the {N, ...} circle(s) on

    Returns
    -------
    x_c, y_c : {N, ...} ndarray
        The center position for the {N, ...} circle(s)

    Notes
    -----
    the returned arrays will be of the same shape of the input arrays
    """
    x1, x2, x3 = xs
    y1, y2, y3 = ys

    # Speed-up trick
    dist1_sqr = (x1 * x1) + (y1 * y1)
    dist2_sqr = (x2 * x2) + (y2 * y2)
    dist3_sqr = (x3 * x3) + (y3 * y3)
    diffy12 = y1 - y2
    diffy23 = y2 - y3
    diffy31 = y3 - y1

    den = 2.0 * (x1 * diffy23 + x2 * diffy31 + x3 * diffy12)
    x_c = dist1_sqr * diffy23 + dist2_sqr * diffy31 + dist3_sqr * diffy12
    y_c = dist1_sqr * (x3 - x2) + dist2_sqr * (x1 - x3) + dist3_sqr * (x2 - x1)

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        x_c /= den
        y_c /= den

    return x_c, y_c