import math


def angle_from_goal(x, y, gx, gy):
    """
    Computes angle between straight shot and goal line.
    Note: This method naively computes a straight shot from (x, y) to (gx, xy)
    but in HaxBall, it is common for players to bounce the ball off of walls and
    take another trajectory. Any point on the goal line can be used, such as the
    midpoint between the posts.
    Args:
        x: X-coordinate where ball was kicked from.
        y: Y-coordinate where ball was kicked from.
        gx: X-coordinate of point on goal line.
        gy: Y-coordinate of point on goal line.
    Returns:
        Angle between straight shot and goalline in radians,
        e.g., 0 is a straight shot along the goal line,
        Pi/2 is a straight shot perpendicular to the goal line.
    """
    # Use absolute value to restrict angle between [0, Pi/2].
    dx = float(abs(x - gx))
    dy = float(abs(y - gy))
    # Avoid division by zero error.
    angle = math.atan(dx / dy) if dy > 0 else math.pi / 2.0
    return angle