RUST · MOTORSPORT TIRE PHYSICS

tlab-vehicle-physics-rs — Pacejka Magic Formula Tire Kinetics & Slip Physics in Rust

tlab-vehicle-physics-rs is a pure Rust tire and vehicle dynamics solver implementing Hans Pacejka's empirical Magic Formula for longitudinal traction, lateral cornering force, and self-aligning torque. It models load sensitivity, camber thrust, and friction-circle combined slip for realistic racing and drift simulations.

$ cargo add tlab-vehicle-physics-rs
GitHub ↗

Live Pacejka Curve Plotter

Tune Hans Pacejka's semi-empirical parameters in real time and observe live friction response and cornering stiffness.

Operating Slip (α)
6.0°
Lateral Force (Fy)
5,420 N
Cornering Stiffness (Cα)
1,240 N/deg
Peak Slip Angle
8.2°
Tire Presets
Active Slip Angle Scrubber ($\alpha$) 6.0°
Stiffness Factor ($B$) 10.0
Shape Factor ($C$) 1.60
Peak Friction Factor ($D = \mu \cdot F_z$) 1.35
Curvature Factor ($E$) -0.60
Normal Load ($F_z$) 4,500 N
Traction State
100% GRIP
Demand ($F_{\text{total}}$)
3,850 N
Grip Utilization
68.2%
Slide Friction (μ_eff)
1.28
Longitudinal Slip Ratio ($\kappa$) - Braking / Acceleration 0.00
-1.0 (Full Lockup) 0.0 (Rolling) +1.0 (Burnout)
Lateral Slip Angle ($\alpha$) - Cornering / Drift 0.0°
Drift Trigger Presets
Combined Slip Weighting
$G_{xa}(\alpha) = \cos(C_{xa} \arctan(B_{xa} \alpha))$
$G_{yk}(\kappa) = \cos(C_{yk} \arctan(B_{yk} \kappa))$
Self-Aligning Torque
142 N·m
Pneumatic Trail ($t$)
28.4 mm
FFB Feel
Centering Grip
Slip Angle Scrubber ($\alpha$) 4.0°
Wheel Camber Angle ($\gamma$) -2.0°
Negative camber introduces lateral camber thrust $F_{y,\gamma} = C_\gamma \cdot \gamma \cdot F_z$.

The Secret of Drift Force Feedback

At low slip angles ($\alpha < 5^\circ$), pneumatic trail acts behind the tire patch, producing strong self-centering torque ($M_z$). As slip approaches peak grip ($\approx 7^\circ$), $M_z$ peaks and then rapidly decays to near-zero as trail vanishes. In deep drift angles ($\alpha > 12^\circ$), torque relaxes, naturally rotating the steering wheel into counter-steer!

Core Subsystems

TLabVehiclePhysics C# translation ported to idiomatic, memory-safe, zero-allocation Rust.

📐

Hans B. Pacejka Magic Formula

Semi-empirical formulation governing tire adhesion through slip stiffness ($B$), curve shape ($C$), peak friction ($D$), curvature ($E$), and horizontal/vertical shifts.

$$y(x) = D \sin(C \arctan(Bx_1 - E(Bx_1 - \arctan Bx_1))) + S_v$$
⚡

Slip Angle & Ratio Kinematics

Calculates longitudinal slip ratio $\kappa$ and lateral slip angle $\alpha$ with numerical low-speed singularity regularization to guarantee rock-solid standstill stability.

$$\kappa = \frac{\omega r - v_x}{\max(|v_x|, v_{\text{reg}})}, \quad \alpha = \arctan\left(\frac{v_y}{|v_x|}\right)$$
⭕

Combined Slip & Friction Ellipse

Coupled Pacejka interaction attenuation factors $G_{xa}$ and $G_{yk}$. Acceleration wheelspin attenuates lateral cornering grip; lateral slide reduces braking capability.

$$F_x = F_{x0} \cdot G_{xa}(\alpha), \quad F_y = F_{y0} \cdot G_{yk}(\kappa)$$
🔄

Pneumatic Trail & Counter-Steer

Realistic contact patch center-of-pressure offset. Produces accurate self-aligning torque ($M_z$) for force feedback steering wheels and authentic drift counter-steer.

$$M_z = -t(\alpha) \cdot F_y + M_{zr}(\alpha, \gamma)$$
⚖️

Normal Load Sensitivity

Tire friction coefficient diminishes as normal load $F_z$ increases, accurately simulating vehicle weight transfer, body roll, and understeer/oversteer balance.

$$\mu(F_z) = \mu_0 \cdot \left(1 - k_{\text{load}} \cdot \frac{F_z - F_{z0}}{F_{z0}}\right)$$
🏎️

Progressive Drift Breakaway

Smooth exponential transition from static peak friction $\mu_{\text{peak}}$ towards kinetic sliding friction $\mu_{\text{slide}}$ when tire traction limit is exceeded.

$$\mu_{\text{eff}} = \mu_{\text{slide}} + (\mu_{\text{peak}} - \mu_{\text{slide}}) \cdot e^{-\beta (\text{util}-1)^2}$$

Mathematical Formulations

The analytical equations driving each computation in the Rust crate.

C# Direct Evaluation Variant

Direct formula evaluated in TLabVehiclePhysics C# port:

$$F(x) = D \sin(C \arctan(B x - E \arctan(B x - \arctan(B x))))$$

MultiPacejka 2D Load Table

Bilinear interpolation between discrete load-dependent Pacejka curve presets across vertical wheel force slices $F_{z,1}, F_{z,2}, \dots, F_{z,n}$.

$$F_{\text{net}} = \text{lerp}(F_{\text{low}}(x), F_{\text{high}}(x), t)$$

Quick Start Guide

Add tlab-vehicle-physics to your project and evaluate full tire kinematics in 5 lines of Rust.

Cargo.toml
[dependencies]
tlab-vehicle-physics = "0.1"
glam = "0.29"
main.rs
use tlab_vehicle_physics::prelude::*;

fn main() {
    // 1. Instantiate a high-performance tire model with Pacejka coefficients
    let tire = TireModel::default();

    // 2. Supply instantaneous wheel kinematics from physics engine
    let angular_velocity = 32.0;                // rad/s (~305 RPM)
    let wheel_radius = 0.35;                    // 35 cm rolling radius
    let longitudinal_velocity = 10.0;           // 10 m/s (36 km/h) forward
    let lateral_velocity = 1.2;                 // 1.2 m/s sideways drift
    let normal_load = 4_200.0;                  // 4,200 N normal force
    let camber_angle_rad = -1.5_f32.to_radians(); // -1.5° camber

    // 3. Evaluate comprehensive tire kinetics
    let output = tire.evaluate(
        angular_velocity, wheel_radius,
        longitudinal_velocity, lateral_velocity,
        normal_load, camber_angle_rad,
    );

    println!("Longitudinal Force Fx: {:.1} N", output.longitudinal_force);
    println!("Lateral Force Fy: {:.1} N", output.lateral_force);
    println!("Self-Aligning Torque Mz: {:.2} N·m", output.aligning_torque);
    println!("Grip Utilization: {:.1}%", output.grip_utilization * 100.0);
    println!("Is Sliding/Drifting: {}", output.is_sliding);
}

Nanosecond Pacejka Dynamics vs. Unity C#

High-performance empirical tire kinetics benchmarked against Unity TLabVehiclePhysics. View Full BENCHMARKS.md →

Single Wheel Pacejka Step
75.7 ns / tire
244× faster than Unity C# (~18.5 µs)
4-Wheel Vehicle Rig
292.9 ns / vehicle
3.41 Million vehicles/sec capacity
100-Car Fleet at 60 FPS
23.6 µs (42,362 FPS)
0.14% of 16.6ms 60 FPS frame budget
Raw Pacejka Curve
38.7 ns / eval
25.85 Million evals/sec (Zero Alloc)

Automated Test Suite

100% test coverage across all Pacejka formulas and slip kinematics.

18 Tests Passed
0 failed · 0 ignored · 5 integration suites
✓ ALL TESTS PASSING
accuracy_test 3/3
✓ test_pacejka_analytical_magic_formula_exactness (RMSE < 10⁻⁵)
✓ test_friction_circle_invariance (100% envelope bound)
✓ test_cornering_stiffness_and_peak_force
combined_slip_tests 3/3
✓ test_normal_load_sensitivity
✓ test_pacejka_combined_slip_weighting
✓ test_friction_circle_limit
pacejka_tests 4/4
✓ test_pacejka_magic_formula_evaluation
✓ test_tlab_csharp_formula_evaluation
✓ test_pacejka_shifts
✓ test_multi_pacejka_interpolation
slip_tests 4/4
✓ test_longitudinal_slip_ratio_driving_and_braking
✓ test_lateral_slip_angle
✓ test_slip_ratio_zero_speed_regularization
✓ test_combined_slip_state_evaluator
tire_forces_tests 4/4
✓ test_camber_thrust
✓ test_pneumatic_trail_and_aligning_torque
✓ test_full_tire_evaluation
✓ test_zero_normal_load