# Path: skyfield/functions.py
# def length_of(xyz):
#     """Given a 3-element array |xyz|, return its length.
# 
#     The three elements can be simple scalars, or the array can be two
#     dimensions and offer three whole series of x, y, and z coordinates.
# 
#     """
#     return sqrt((xyz * xyz).sum(axis=0))


from numpy import sqrt
from .functions import length_of
    from sympy import symbols, atan2, acos, rot_axis1, rot_axis3, Matrix
    from sympy import cse, numbered_symbols
    # Apply rotations to produce an "o" = output vector.
    v = Matrix([x, y, z])
    xo, yo, zo = rot_axis1(around_x) * rot_axis3(-around_z) * v

    # Which we then use the stereographic projection to produce the
    # final "p" = plotting coordinates.
    xp = xo / (1 - zo)
    yp = yo / (1 - zo)

    return xp, yp

def _optimize(expressions):
    commons, outputs = cse(
        expressions,
        numbered_symbols('t'),
        optimizations='basic',
    )
    for symbol, expr in commons:
        print(symbol, '=', expr)
    print()
    for expr in outputs:
        print(expr)

def build_stereographic_projection(center):
    """Compute *x* and *y* coordinates at which to plot the positions."""

    # TODO: Computing the center should really be done using
    # optimization, as in:
    # https://math.stackexchange.com/questions/409217/
    p = center.position.au

# Path: skyfield/functions.py
# def length_of(xyz):
#     """Given a 3-element array |xyz|, return its length.
# 
#     The three elements can be simple scalars, or the array can be two
#     dimensions and offer three whole series of x, y, and z coordinates.
# 
#     """
#     return sqrt((xyz * xyz).sum(axis=0))


# Path: skyfield/projections.py
from numpy import sqrt
from .functions import length_of
    from sympy import symbols, atan2, acos, rot_axis1, rot_axis3, Matrix
    from sympy import cse, numbered_symbols

    # Apply rotations to produce an "o" = output vector.
    v = Matrix([x, y, z])
    xo, yo, zo = rot_axis1(around_x) * rot_axis3(-around_z) * v

    # Which we then use the stereographic projection to produce the
    # final "p" = plotting coordinates.
    xp = xo / (1 - zo)
    yp = yo / (1 - zo)

    return xp, yp

def _optimize(expressions):
    commons, outputs = cse(
        expressions,
        numbered_symbols('t'),
        optimizations='basic',
    )
    for symbol, expr in commons:
        print(symbol, '=', expr)
    print()
    for expr in outputs:
        print(expr)

def build_stereographic_projection(center):
    """Compute *x* and *y* coordinates at which to plot the positions."""

    # TODO: Computing the center should really be done using
    # optimization, as in:
    # https://math.stackexchange.com/questions/409217/
    p = center.position.au

    u = p / length_of(p)