Esempio n. 1
0
def get_center_circle(full_court=True, rotate=False, rotation_dir='ccw'):
    """
    Generate the dataframe for the points that comprise the center circle as
    specified in Rule 1, Section 4, Article 1 of the NCAA rule book

    Returns
    -------
    center_circle: a pandas dataframe containing the points that comprise the
        center circle of the court
    """
    # Draw the right outer semicircle, then move in 2" per the NCAA's required
    # line thickness, and draw inner semicircle. Doing it this way alleviates
    # future fill issues.
    center_circle = helper.create_circle(d=12, start=1 / 2, end=3 / 2).append(
        pd.DataFrame({
            'x': [0],
            'y': [6 - (2 / 12)]
        })).append(
            helper.create_circle(d=12 - (4 / 12), start=3 / 2,
                                 end=1 / 2)).append(
                                     pd.DataFrame({
                                         'x': [0],
                                         'y': [-6]
                                     }))

    if full_court:
        # Reflect the x coordinates over the y axis
        center_circle = center_circle.append(
            transform.reflect(center_circle, over_y=True))

    # Rotate the coordinates if necessary
    if rotate:
        center_circle = transform.rotate(center_circle, rotation_dir)

    return center_circle
Esempio n. 2
0
def get_restricted_area_arcs(full_court=True,
                             rotate=False,
                             rotation_dir='ccw'):
    """
    Generate the dataframe for the points that comprise the restricted-area
    arcs as specified in Rule 1, Section 8 of the NCAA rule book

    Returns
    -------
    restricted_area_arcs: a pandas dataframe of the restricted-area arcs
    """
    # The restricted area arc is an arc of radius 4' from the center of the
    # basket, and extending in a straight line to the front face of the
    # backboard, and having thickness of 2"
    restricted_area_arc = pd.DataFrame({
        'x': [-43],
        'y': [-4 - (2 / 12)]
    }).append(
        helper.create_circle(center=(-41.75, 0),
                             d=8 + (4 / 12),
                             start=-1 / 2,
                             end=1 / 2)).append(
                                 pd.DataFrame({
                                     'x': [-43, -43],
                                     'y': [4 + (2 / 12), 4]
                                 })).append(
                                     helper.create_circle(
                                         center=(-41.75, 0),
                                         d=8,
                                         start=1 / 2,
                                         end=-1 / 2)).append(
                                             pd.DataFrame({
                                                 'x': [-43, -43],
                                                 'y': [-4, -4 - (2 / 12)]
                                             }))

    if full_court:
        # Reflect the x coordinates over the y axis
        restricted_area_arc = restricted_area_arc.append(
            transform.reflect(restricted_area_arc, over_y=True))

    # Rotate the coordinates if necessary
    if rotate:
        restricted_area_arc = transform.rotate(rotation_dir=rotation_dir,
                                               df=restricted_area_arc)

    return restricted_area_arc
Esempio n. 3
0
def get_w_three_pt_lines(full_court=True, rotate=False, rotation_dir='ccw'):
    """
    Generate the dataframe for the points that comprise the three-point line
    as specified in Rule 1, Section 7 of the NCAA rule book. These points are
    the women's three-point line, and also where the men's three-point line was
    prior to the 2019-2020 season

    Returns
    -------
    w_three_pt_lines: a pandas dataframe of the three-point line
    """
    # This can be computed similarly to how the men's line was computed
    w_three_pt_line = pd.DataFrame({
        'x': [-47],
        'y': [-20.75]
    }).append(
        helper.create_circle(center=(-41.75, 0),
                             d=41.5,
                             start=-1 / 2,
                             end=1 / 2)).append(
                                 pd.DataFrame({
                                     'x': [-47, -47],
                                     'y': [20.75, 20.75 - (2 / 12)]
                                 })).append(
                                     helper.create_circle(
                                         center=(-41.75, 0),
                                         d=41.5 - (4 / 12),
                                         start=1 / 2,
                                         end=-1 / 2)).append(
                                             pd.DataFrame({
                                                 'x': [-47, -47],
                                                 'y':
                                                 [-20.75 + (2 / 12), -20.75]
                                             }))

    if full_court:
        # Reflect the x coordinates over the y axis
        w_three_pt_line = w_three_pt_line.append(
            transform.reflect(w_three_pt_line, over_y=True))

    # Rotate the coordinates if necessary
    if rotate:
        w_three_pt_line = transform.rotate(w_three_pt_line, rotation_dir)

    return w_three_pt_line
Esempio n. 4
0
def get_free_throw_circles(full_court=True, rotate=False, rotation_dir='ccw'):
    """
    Generate the dataframe for the points that comprise the free-throw circles
    as specified on the court diagram in the NCAA rule book

    Returns
    -------
    free_throw_circles: a pandas dataframe of the free-throw circle
    """
    # The free-throw circle is 6' in diameter from the center of the free-throw
    # line (exterior)
    free_throw_circle = helper.create_circle(
        center=(-28, 0), start=-1 / 2, end=1 / 2,
        d=12).append(pd.DataFrame({
            'x': [-28],
            'y': [6]
        })).append(
            helper.create_circle(center=(-28, 0),
                                 start=1 / 2,
                                 end=-1 / 2,
                                 d=12 - (4 / 12))).append(
                                     pd.DataFrame({
                                         'x': [-28],
                                         'y': [-6]
                                     }))

    if full_court:
        # Reflect x coordinates over y axis
        free_throw_circle = free_throw_circle.append(
            transform.reflect(free_throw_circle, over_y=True))

    # Rotate the coordinates if necessary
    if rotate:
        free_throw_circle = transform.rotate(free_throw_circle, rotation_dir)

    return free_throw_circle
Esempio n. 5
0
def get_goals(full_court=True, rotate=False, rotation_dir='ccw'):
    """
    Generate the dataframe for the points that comprise the goals as specified
    in Rule 1, Sections 14 and 15 of the NCAA rule book

    Returns
    -------
    goals: a pandas dataframe of the goals
    """
    # Get the starting angle of the ring. The connector has a width of 5", so
    # 2.5" are on either side. The ring has a radius of 9", so the arcsine of
    # these measurements should give the angle at which point they connect
    start_angle = np.pi - math.asin(2.5 / 9)

    # The ending angle of the ring would be the negative of the starting angle
    end_angle = -start_angle

    # Define the coordinates for the goal
    goal = pd.DataFrame({
        'x': [-43, -41.75 - ((9 / 12) * math.cos(start_angle))],
        'y': [2.5 / 12, 2.5 / 12]
    }).append(
        helper.create_circle(
            center=(-41.75, 0),
            start=start_angle,
            end=end_angle,
            d=1.5 + (4 / 12))).append(
                pd.DataFrame({
                    'x':
                    [-41.75 - ((9 / 12) * math.cos(start_angle)), -43, -43],
                    'y': [-2.5 / 12, -2.5 / 12, 2.5 / 12]
                }))

    if full_court:
        # Reflect x coordinates over y axis
        goal = goal.append(transform.reflect(goal, over_y=True))

    # Rotate the coordinates if necessary
    if rotate:
        goal = transform.rotate(goal, rotation_dir)

    return goal
Esempio n. 6
0
def get_nets(full_court=True, rotate=False, rotation_dir='ccw'):
    """
    Generate the dataframe for the points that comprise the rings as specified
    in Rule 1, Section 14, Article 2 of the NCAA rule book

    Returns
    -------
    nets: a pandas dataframe of the nets
    """
    # The ring's center is 15" from the backboard, and 63" from the baseline,
    # which means it is centered at (+/-41.75, 0). The ring has an interior
    # diameter of 18", which is where the net is visible from above
    net = helper.create_circle(center=(-41.75, 0), d=1.5)

    if full_court:
        # Reflect x coordinates over y axis
        net = net.append(transform.reflect(net, over_y=True))

    # Rotate the coordinates if necessary
    if rotate:
        net = transform.rotate(net, rotation_dir)

    return net
Esempio n. 7
0
def get_m_three_pt_lines(full_court=True, rotate=False, rotation_dir='ccw'):
    """
    Generate the dataframe for the points that comprise the three-point line
    as specified in Rule 1, Section 7 of the NCAA rule book. These points are
    the men's three-point line after being moved back prior to the 2019-2020
    season

    Returns
    -------
    m_three_pt_lines: a pandas dataframe of the three-point line
    """
    # First, a bit of math is needed to determine the starting and ending
    # angles of the three-point arc, relative to 0 radians. Since in the end,
    # the angle is what matters, the units of measure do not. Inches are easier
    # to use for this calculation. The angle begins 9' 10 3/8" from the
    # interior edge of the endline
    start_x = (9 * 12) + 10 + (3 / 8)

    # However, the rule book describes the arc as having a radius of 22' 1.75"
    # from the center of the basket. The basket's center is 63" away from the
    # interior of the endline, so this must be subtracted from our starting x
    # position to get the starting x position *relative to the center of the
    # basket*
    start_x -= 63
    radius_outer = (22 * 12) + 1.75

    # From here, the calculation is relatively straightforward. To determine
    # the angle, the inverse cosine is needed. It will be multiplied by pi
    # so that it can be passed to the create_circle() function
    start_angle_outer = math.acos(start_x / radius_outer) / np.pi
    end_angle_outer = -start_angle_outer

    # The same method can be used for the inner angles, however, since the
    # inner radius will be traced from bottom to top, the angle must be
    # negative to start
    radius_inner = (22 * 12) + 1.75 - 2
    start_angle_inner = -math.acos(start_x / radius_inner) / np.pi
    end_angle_inner = -start_angle_inner

    # According to the rulebook, the three-point line is 21' 7 7/8" in the
    # corners
    m_three_pt_line = pd.DataFrame({
        'x': [-47],
        'y': [21 + ((7 + (7 / 8)) / 12)]
    }).append(
        helper.create_circle(
            center=(-41.75, 0),
            d=2 * (((22 * 12) + 1.75) / 12),
            start=start_angle_outer,
            end=end_angle_outer)).append(
                pd.DataFrame({
                    'x': [-47, -47, -47 + (((9 * 12) + 10 + (3 / 8)) / 12)],
                    'y': [
                        -21 - ((7 + (7 / 8)) / 12),
                        -21 - ((7 + (7 / 8)) / 12) + (2 / 12),
                        -21 - ((7 + (7 / 8)) / 12) + (2 / 12)
                    ]
                })).append(
                    helper.create_circle(
                        center=(-41.75, 0),
                        d=2 * ((((22 * 12) + 1.75) / 12) - (2 / 12)),
                        start=start_angle_inner,
                        end=end_angle_inner)).append(
                            pd.DataFrame({
                                'x': [
                                    -47 + (((9 * 12) + 10 + (3 / 8)) / 12),
                                    -47, -47
                                ],
                                'y': [
                                    21 + ((7 + (7 / 8)) / 12) - (2 / 12),
                                    21 + ((7 + (7 / 8)) / 12) - (2 / 12),
                                    21 + ((7 + (7 / 8)) / 12)
                                ]
                            }))

    if full_court:
        # Reflec the x coordinates over the y axis
        m_three_pt_line = m_three_pt_line.append(
            transform.reflect(m_three_pt_line, over_y=True))

    # Rotate the coordinates if necessary
    if rotate:
        m_three_pt_line = transform.rotate(rotation_dir=rotation_dir,
                                           df=m_three_pt_line)

    return m_three_pt_line