INNER CODE UNIT · Python
trajectory_fit
chonyy/AI-basketball-analysis · src/utils.py:66
def trajectory_fit(balls, height, width, shotJudgement, fig):
x = [ball[0] for ball in balls]
y = [height - ball[1] for ball in balls]
try:
params = curve_fit(fit_func, x, y)
[a, b, c] = params[0]
except:
print("fitting error")
a = 0
b = 0
c = 0
x_pos = np.arange(0, width, 1)
y_pos = [(a * (x_val ** 2)) + (b * x_val) + c for x_val in x_pos]
if(shotJudgement == "MISS"):
plt.plot(x, y, 'ro', figure=fig)
plt.plot(x_pos, y_pos, linestyle='-', color='red',