# Q-9: Fit a parabola to a flight and recover gravity

Data-Driven Athletics tutorial · Week 3 · Chapter 3 · about 15 min · workflow steps: Statistics, Visualize, Features

Web page: https://apopt.com/course/tutorials/q09-parabola-gravity/ · Data: https://apopt.com/data/tutorials/q09-parabola-gravity/

## The decision

You have a jump height from a slow-motion clip. Before you report it, check the clock and the
scale it rests on, using the one number in a jump you know before you film it: gravity.

## The raw data

- `raw/jump2_keypoints_yolo26s.csv`: pose keypoints (17 joints, x, y in pixels and confidence) for every frame of the course's example jump, filmed at 120 frames per second and stored at 30 Written by CS-1's pose step (YOLO26s) from `jump2_120fps.mp4`; the clip shows a person and is not published, the table shows no one.

### Gravity is the one number you know before you film

In flight the center of mass follows a parabola, y = c₀ + c₁t + c₂t², with c₂ = −g/2
(Section 3.4.4). Fit that parabola to a tracked point and read off a "gravity",
g_fit = −2c₂. You already know the answer, 9.81 m/s², so the fit checks the two things you
supplied: the **scale** that turns pixels into meters and the **frame rate** that turns frame
numbers into seconds (Section 10.2, "The arc as a check on scale and frame rate").

The file is the pose table of the course's example jump from CS-1 (filmed at 120 frames per
second, stored at 30). Take the hip midpoint through the frames in the air, 82 to 122, leaving a
couple of frames at each end where the feet are still near the ground.

*Predict first:* Which way does pixel y run, and what sign should the fitted c₂ have once you flip it to "up is up"?

```python
import numpy as np
import pandas as pd

kp = pd.read_csv("raw/jump2_keypoints_yolo26s.csv")
air = kp[(kp["frame"] >= 82) & (kp["frame"] <= 122)]
hip_px = -(air["l_hip_y"] + air["r_hip_y"]) / 2      # minus: image y grows downward
PX_PER_M = 859                                        # CS-1's scale (stature 1.70 m, assumed)
y = (hip_px - hip_px.iloc[0]).to_numpy() / PX_PER_M   # meters above the first frame
frames = air["frame"].to_numpy() - 82
print(f"{len(frames)} frames; the hips rise {100 * y.max():.1f} cm and come back to {100 * y[-1]:.1f} cm")
```

Output:

```
41 frames; the hips rise 17.9 cm and come back to 0.1 cm
```

### Fit the parabola on both clocks

*Predict first:* If you use the file's 30 frames per second instead of the camera's 120, how many times too small will "gravity" come out?

```python
for fps in (30, 120):
    c2, c1, c0 = np.polyfit(frames / fps, y, 2)
    print(f"time = frame / {fps:3d}: g_fit = {-2 * c2:6.2f} m/s²,  takeoff speed {c1:.2f} m/s")
g30 = -2 * np.polyfit(frames / 30, y, 2)[0]
g120 = -2 * np.polyfit(frames / 120, y, 2)[0]
print(f"ratio {g120 / g30:.1f}; at 120 fps the fit is {g120 / 9.80665:.2f} times true gravity")
```

Output:

```
time = frame /  30: g_fit =   0.75 m/s²,  takeoff speed 0.51 m/s
time = frame / 120: g_fit =  12.08 m/s²,  takeoff speed 2.02 m/s
ratio 16.0; at 120 fps the fit is 1.23 times true gravity
```

On the file's clock the jumper falls with a gravity of 0.75 m/s², sixteen times too small:
every time is four times too long, and gravity divides by time squared. On the camera's clock the
answer is 12.1 m/s², the right size but 23% too large. Section 10.2 says how to read that:

g_fit / g = (k / k_used) × (f_used / f)²

where k and f are the true scale and frame rate and k_used and f_used the ones you assumed.
A factor of 1.23 is not a slow-motion error (those come in factors of 4, 16, 64). It points at
the scale (a stature nobody measured, a hand-held camera), at the hips not being the center of
mass, or at a frame rate a little below 120. CS-3 untangles them.

### One chart

```python
import matplotlib.pyplot as plt

t = frames / 120
c = np.polyfit(t, y, 2)
fig, ax = plt.subplots(figsize=(6.4, 3.6))
ax.plot(t, 100 * y, "o", ms=5, color="k", label="hip midpoint")
tt = np.linspace(0, t.max(), 100)
ax.plot(tt, 100 * np.polyval(c, tt), "-", color="0.5", lw=2, label=f"parabola, g_fit = {-2 * c[0]:.1f} m/s²")
ax.set(xlabel="time from frame 82 (s, at 120 frames per second)", ylabel="hip height (cm)")
ax.legend(loc="lower center")
plt.tight_layout()
print(f"residual sd {100 * np.std(y - np.polyval(c, t)):.1f} cm; implied frame rate if the scale is right: "
      f"{120 * np.sqrt(9.80665 / (-2 * c[0])):.0f} fps")
```

Output:

```
residual sd 1.0 cm; implied frame rate if the scale is right: 108 fps
```

![Hip height in centimeters against time in flight in seconds (at 120 frames per second), 41 points rising about 18 cm and falling back, with the fitted parabola drawn through them; the legend gives the fitted gravity, 12.1 m/s squared.](https://apopt.com/course/tutorials/q09-parabola-gravity/c05-1.png)

The points hug the parabola to within about a centimeter, so the fit itself is sound; it is the
inputs that are in doubt. If the scale were exactly right, the gravity of 12.1 would mean a
frame rate of 108, not 120. Neither the scale nor the posture is known well enough here to say
which it is, but a factor of sixteen would have been impossible to miss.

**For the athlete:** "Before trusting any height from your slow-motion clip, we check that your
flight follows gravity; at the file's frame rate it doesn't, at the camera's it nearly does."

## With your own data

Use the keypoint table of your own jump (CS-1, Step 1), pick the frames in the air, and fit the
parabola with your measured stature for the scale. A result within about 10% of 9.81 m/s² means
your scale and frame rate are both plausible.

## References

- *Data-Driven Athletics*, Chapter 3, Predicting the whole arc (Section 3.4.4); Chapter 10, The arc as a check on scale and frame rate (Section 10.2).

---
Text CC BY 4.0, code MIT. IRSRI Sports Research Institute.
