File size: 968 Bytes
93a3e92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# backend/utils/drs_logic.py
def predict_impact(ball_positions: list) -> tuple:
    """
    Predict the ball's impact point on the stumps or pad based on trajectory.
    Returns (x, y) coordinates of the predicted impact point.
    """
    if not ball_positions or len(ball_positions) < 2:
        return None
    
    x1, y1 = ball_positions[-2]
    x2, y2 = ball_positions[-1]
    
    stump_y = 600  # Adjust based on video calibration
    if y2 == y1:
        return None
    
    slope = (x2 - x1) / (y2 - y1)
    impact_x = x1 + slope * (stump_y - y1)
    
    return (impact_x, stump_y)

def is_drs_out(impact_point: tuple) -> bool:
    """
    Determine if the ball meets DRS criteria for an Out decision.
    Returns True (Out) or False (Not Out).
    """
    if impact_point is None:
        return False
    
    x, y = impact_point
    stump_x_min, stump_x_max = 400, 800  # Adjust based on video calibration
    
    return stump_x_min <= x <= stump_x_max