Part 2 of Football Math with RoboCup 2D: a rolling ball, a famous school formula, and why it matters for chips

About this part. I am a high-school IB student, and I build hardware projects on my PYNQ-Z2 FPGA board. I used an AI assistant to help me draft the text and code. The ideas, the structure and the final decisions are mine.

The numbers in this article come from a literature report about the manual and the rcssserver 19.0.0 code. I have not yet compared each one with the original source.

For this article I ran the build script and read the literature report. The Python demos are my own toy models. All code is here: https://github.com/ziydin/robocup2d-math-series

I love football, and I am trying to understand its theory and its basic logic. That is why I wanted to look deeply at the math of the game. I am also interested in hardware engineering. I want to build a bridge between the two fields, so that I can see the whole picture.

The bike that does not stop at once

Stop pedalling on a flat road. Your bike does not stop at once. It rolls on and slows down little by little.

A kicked ball in the RoboCup 2D simulator does the same. Each cycle it keeps 94% of its speed and loses 6%. (A cycle is one step of the simulation, nominally 100 ms. See Part 1.)

So here is today's question: if I kick the ball, where will it stop?

My first guess was "it rolls forever", because it never loses all its speed. That guess is wrong, and the reason is one of the nicest ideas in school math: the geometric series.

Version note: all values are for rcssserver 19.0.0 (25 March 2024). Some manual tables differ from this code, for example back_dash_rate = 0.7 and effort_dec = 0.005 in the code (details in Part 1).

The idea in plain words

The word decay here means "slowing down by the same fraction every cycle". The ball's decay is 0.94. The player's decay is 0.4.

Distances are in simulator units, which I call metres. Speeds are in metres per cycle. The ball's speed cap is 3.0 per cycle. At 10 cycles per second that is 30 m/s.

My update rule [Toy]. For a rolling ball that nobody touches, I use this order in each cycle:

  1. move: position = position + velocity,
  2. slow down: velocity = decay × velocity.

My source describes the same order, but I have not checked it in the code. So I mark it as my assumption.

xt+1​=xt​+vt​,vt+1​=d⋅vt​

The math, step by step

Step 1: the speed

Each cycle multiplies the speed by d. After n cycles we multiplied n times. [Derived]

vn​=v0​⋅dn

The speed gets smaller and smaller, but it never becomes exactly zero.

Left: the ball speed falls slowly along a smooth curve and crosses a dashed slow line. Right: the player speed jumps to the cap and drops almost at once after it stops pushing.
Figure 1. Speed per cycle. The ball keeps 94% each cycle, the player only 40%. Toy model.

Step 2: the distance, and the "multiply and subtract" trick

The ball moves v₀ in the first cycle, v₀·d in the second, v₀·d² in the third, and so on. So the distance after n cycles is v₀ times this sum:

S=1+d+d2+⋯+dn−1

Adding many terms is slow. Here is a trick to add them all at once. Multiply the whole sum by d:

d⋅S=d+d2+⋯+dn−1+dn

Now subtract the second line from the first. Almost every term appears in both lines, so they cancel. Only the first term of S and the last term of dS survive:

S−d⋅S=1−dn⟹S=1−d1−dn​

That is the whole proof. ∎ Multiply by v₀, and we get the closed form. A closed form is a formula that gives the answer directly, without a loop. [Derived]

xn​=v0​⋅1−d1−dn​

My script compares this formula with a step-by-step loop in 662 cases. The largest difference is 7.8 × 10⁻¹⁴, which is just computer rounding.

Two rows of shrinking bars. The bottom row is the top row moved one step right. Grey bars match and cancel, leaving one blue bar and one red bar.
Figure 3. The multiply and subtract trick. Only the first bar of S and the last bar of d times S survive.

Step 3: the ceiling

When n gets very large, dⁿ gets close to zero. So the distance gets close to a fixed number. [Derived]

x∞​=1−dv0​​=0.063.0​=50 m

So with the top speed of 3.0 and decay 0.94, a ball can never roll more than 50 m in my toy (no noise, no players in the way). When I first saw this, I did not believe it. So I made the script check it with a long loop.

One honest detail: one push from rest is limited by the acceleration cap of 2.7. A ball kicked from rest at that speed stops at 45 m. The 50 m case needs a ball that already moves at the top speed.

The same idea gives a handy rule. The distance still left to roll is always the current speed times 16.7: [Derived]

x∞​−xn​=1−dvn​​≈16.7⋅vn​

Two rising curves of distance against cycle that flatten under dotted ceiling lines, with a vertical line at one half-life.
Figure 2. The distance grows but never passes v0 / (1 − d), which is 50 m at top speed. Toy model, no noise.

Step 4: when is the ball "slow"? Logarithms

Let me call a ball "slow" when its speed is below 0.1 per cycle (my own choice). We need v₀·dⁿ < s. Take the logarithm of both sides. A logarithm turns "power" into "times", so we can get n down from the top. Careful: ln d is negative, so the inequality sign flips. [Derived]

v0​⋅dn<s⟺n>lndln(s/v0​)​

For a ball at 3.0, the right side is 54.97, so the ball is slow from cycle 55 (about 5.5 s). By then it has already rolled 48.3 m, which is 96.7% of the ceiling.

A nice way to feel this is the half-life: how many cycles until the speed is halved. [Derived]

dh=21​⟺h=−lndln2​

For the ball, h ≈ 11.2 cycles (about 1.12 s). After one half-life the ball has covered 50% of its total distance. After two half-lives, 75%. For a player, h ≈ 0.76 cycles: less than one cycle!

Step 5: the inverse problem

Now turn the question around. A teammate stands D metres away. What kick speed do I need?

To stop exactly at D, use the ceiling formula backwards. [Derived]

v0​=D⋅(1−d)

For D = 20 m: v₀ = 1.2.

To arrive at D after exactly n cycles, solve the closed form for v₀. [Derived]

v0​=1−dnD⋅(1−d)​

For D = 20 m and n = 10: v₀ = 2.60. The ball is still moving at 1.40 when it arrives, so the teammate must control it.

What is the fastest possible arrival? Use the biggest kick from rest, 2.7, and solve for n. [Derived]

nmin​=⌈lndln(1−D(1−d)/amax​)​⌉

For 20 m the right side is 9.50, so the fastest arrival is 10 cycles. Arriving in 9 cycles would need 2.81, which is above the cap. And 5 cycles would need 4.51: impossible. In 5 cycles, even the biggest kick only covers 12.0 m.

Step 6: why players stop almost at once

A player has decay 0.4. It keeps only 40% of its speed each cycle. In my toy the player pushes with the full acceleration 1.0 every cycle. Then the speed cap 1.05 applies. [Toy]

ut​=min(vt​+a, vmax​),xt+1​=xt​+ut​,vt+1​=dp​⋅ut​
  • Cycle 1: speed 1.
  • Cycle 2: already at the cap, 1.05.

Without the cap, the speed would settle where "push in" equals "decay out", at 1.67. That is the same geometric sum again: 1 + d + d² + ... = 1/(1 − d) = 1.67. So the cap really matters.

When the player stops pushing, the first move is 0.42, and the total coasting distance is only 0.7 m. A ball with the same rule and the same top speed would coast 16.4 m, about 24 times more. Players are like shopping trolleys on carpet. The ball is like a trolley on ice.

Four ways to look at it

The player: "I stop almost at once, so I can change direction quickly. The ball doesn't. I must plan where it will be."

The mathematician: "Every question today was the same geometric series: speed, distance, ceiling, player top speed."

The programmer: "A closed form replaces a loop. I can ask 'where after 30 cycles?' with one line instead of 30 steps."

The hardware engineer: "Each cycle is one multiply and one add. That is a classic small circuit." (More at the end.)

Noise: the ball wobbles

The simulator adds a small random push to the velocity every cycle. In the v19 code the push has a random direction and a random size, from zero up to r × speed. For the ball r = 0.05, so up to 5% of the speed. For a player r = 0.1. [Sim v19]

v~=vˉ+R⋅(cosΘ,sinΘ),R∼U[0, r∥vˉ∥],Θ∼<...
Source:https://dev.to/wanedar/why-the-ball-stops-decay-and-the-geometric-series-50ad