Closed-Form Aerodynamics: Using Cardano's Formula for Cycling Power-to-Speed

Jun 4, 2022

In late 2020, I wrote about adding aerodynamic drag calculations for the MPower Echelon2 console on Schwinn exercise bikes in my open-source application, Track My Indoor Workout (GitHub repository).

Indoor stationary fitness bikes—such as the Schwinn AC Performance Plus, Schwinn IC4/IC8, Bowflex C6, and the Schwinn x70 series—often broadcast accurate instantaneous power in Watts over Bluetooth Low Energy (BLE) or ANT+. However, many do not broadcast speed, or they report arbitrary, uncalibrated speed values. Without realistic speed modeling, high-wattage indoor sprints produce ridiculously inflated average velocities, which can inadvertently take down real-world Strava King of the Mountain (KOM) segments!

To produce authentic, physically grounded cycling data, Track My Indoor Workout converts raw pedal wattage into realistic virtual velocity in real time. But how do you convert power into speed on a mobile device without killing the battery?


The Physics of Cycling: Power vs. Velocity

When you ride a bicycle, the total mechanical power exerted by your legs () must overcome three physical forces, plus mechanical transmission losses in the drivetrain:

  1. Aerodynamic Drag: where is the aerodynamic drag coefficient, is the cyclist’s frontal area (), is ambient air density (), is ground speed (), and is the headwind component ().

  2. Rolling Resistance: where is the total mass of the rider plus bicycle (), is the coefficient of rolling resistance, and is the road grade (in percent).

  3. Gravity Resistance:

Combining these forces and accounting for mechanical drivetrain loss (, typically ~2%), the total leg power required to sustain ground speed is:

Notice something crucial: because aerodynamic drag force is proportional to the square of velocity (), multiplying force by velocity means aerodynamic power grows with the cube of velocity (). To go 25% faster, you must nearly double your power output!


The Forward vs. Reverse Problem

  • Forward Calculation (Speed Power): Trivial. Plug in velocity and directly evaluate the arithmetic to compute Watts.
  • Reverse Calculation (Power Speed): Non-trivial. Because velocity appears both linearly and cubically, inverting the formula algebraically seemed daunting.

For years, the gold-standard online reference for cycling physics has been the wonderful Cycling Power vs. Speed Calculator by Steve Gribble, a Distinguished Engineer at Google and former Computer Science professor at the University of Washington.

To solve for speed given power, Steve’s original calculator used a successive approximation algorithm (binary search / bisection):

  1. Start with an interval .
  2. Pick the midpoint .
  3. Compute the forward power for .
  4. Halve the search interval based on whether the resulting power is too high or too low.
  5. Repeat up to 100 iterations until the error falls below a small epsilon ().

When I initially implemented this in Track My Indoor Workout (Issue #64), I used Steve’s successive approximation method paired with an in-memory LRU cache to store already-computed power-speed pairs.


The Mobile Bottleneck: Why Successive Approximation Hurts

While an iterative binary search running in time is negligible for occasional web form submissions, mobile fitness tracking presents a very different workload:

  • Live BLE workout data arrives continuously at 1 to 4 Hz.
  • Each incoming packet can have varying cadence, resistance, or power.
  • Running dozens of iterative floating-point approximation loops per second wakes up mobile CPU cores, increases instruction counts, and generates unnecessary thermal and battery drain on smartwatches and smartphones.
  • An iterative search requires arbitrary cutoff thresholds and precision tolerances, meaning slight numerical jitter in speed readouts.

I wanted a true, constant-time analytic solution.


The Breakthrough: Framing the Cubic Polynomial

In June 2022, while expanding workout support for Schwinn x70 bikes (Issue #240 and Issue #287), I sat down to re-examine the full power-velocity equation.

On a stationary trainer or flat track (), the grade terms simplify cleanly:

If we expand the full power equation and gather terms by powers of velocity , the relationship reveals itself as a classic cubic polynomial:

where:

  • (which vanishes when )

Because and for any positive pedaling power, Descartes’ Rule of Signs guarantees that this cubic has exactly one positive real root—the unique physical ground speed!


Enter Gerolamo Cardano (1545)

In 1545, Renaissance Italian mathematician Gerolamo Cardano published his landmark treatise Ars Magna, introducing the first closed-form algebraic formula for solving general cubic equations (incorporating breakthroughs by Scipione del Ferro and Niccolò Tartaglia).

Using Cardano’s method, we define the auxiliary depression coefficients:

From these, we evaluate the intermediate root terms:

And the exact real velocity is obtained directly:

No iteration loops. No epsilon bounds. No approximations. Just a single, deterministic closed-form algebraic evaluation!


Implementation Nuances & Math StackExchange

When translating Cardano’s formula into Dart and JavaScript, a subtle numerical trap arises: pow(x, 1/3) in IEEE 754 floating-point engines returns NaN if .

In the expression for , the value under the cube root, , is frequently negative. In real algebra, the cube root of a negative number is simply negative (), but computer math libraries often treat fractional exponents of negative bases as complex numbers.

I discussed this numerical nuance and alternative hyperbolic formulations on Math StackExchange. The solution in Dart is straightforward—preserve the sign explicitly:

double calculateSpeedFromPower({
  required double power,
  required double athleteWeight,
  required double bikeWeight,
  double dragCoefficient = 0.63,
  double frontalArea = 0.509,
  double airDensity = 1.226,
  double rollingResistance = 0.005,
  double drivetrainLoss = 2.0,
}) {
  if (power <= 0) return 0.0;

  final driveTrainFraction = 1.0 - (drivetrainLoss / 100.0);
  final a = 0.5 * dragCoefficient * frontalArea * airDensity;
  final c = 9.8067 * (athleteWeight + bikeWeight) * rollingResistance;
  final dNeg = driveTrainFraction * power;

  // Cardano depressed cubic coefficients (assuming zero headwind, b = 0)
  final q = c / (3.0 * a);
  final r = dNeg / (2.0 * a);
  final discriminant = (q * q * q) + (r * r);
  final sqrtDisc = sqrt(discriminant);

  const third = 1.0 / 3.0;
  final s = pow(r + sqrtDisc, third).toDouble();

  final rSubE = r - sqrtDisc;
  final t = pow(rSubE.abs(), third).toDouble() * (rSubE < 0 ? -1.0 : 1.0);

  // Exact real velocity in m/s
  return s + t;
}

Collaborating with Steve Gribble

After validating the derivation and testing it across hundreds of simulated power curves, I emailed Steve Gribble to share the Cardano formulation.

Steve was immediately receptive. He recognized the elegance of replacing the iterative bisection loop with an analytic closed form. Shortly thereafter, he updated the Cycling Power vs. Speed Calculator with Cardano’s equations, and generously included an acknowledgment on the page:

“We can now use Cardano’s formula to calculate the first real root of the equation, and hence the value of V that solves the cubic equation. (Thanks go to Csaba Toth for the hint to use Cardano!)”

Seeing that credit live on one of the most widely referenced cycling engineering resources on the web was an absolute honor.


What Changed in Track My Indoor Workout

Integrating Cardano’s formula into Track My Indoor Workout provided immediate architectural and operational benefits:

  1. Execution: Converted an iterative approximation loop into a constant-time closed-form calculation with zero loop overhead.
  2. Infinite Precision: Completely eliminated epsilon approximation errors and numerical speed jitter.
  3. Mobile Energy Efficiency: Drastically reduced CPU cycle counts during active workout logging, preserving vital battery life during 2-to-3-hour indoor endurance sessions.

There is something profoundly satisfying about applying 500-year-old Renaissance algebra to optimize modern mobile Bluetooth fitness trackers!

Comments loading...