<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rem Voorhuis on Medium]]></title>
        <description><![CDATA[Stories by Rem Voorhuis on Medium]]></description>
        <link>https://medium.com/@remvoorhuis?source=rss-4d88d39d4885------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oitmJZT2wd2pf6gr8OwAFA.jpeg</url>
            <title>Stories by Rem Voorhuis on Medium</title>
            <link>https://medium.com/@remvoorhuis?source=rss-4d88d39d4885------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:50:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@remvoorhuis/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to program realistic vehicle physics for realtime environments / games, Part I: simple…]]></title>
            <link>https://medium.com/@remvoorhuis/how-to-program-realistic-vehicle-physics-for-realtime-environments-games-part-i-simple-b4c2375dc7fa?source=rss-4d88d39d4885------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4c2375dc7fa</guid>
            <category><![CDATA[vehicle-simulator]]></category>
            <category><![CDATA[game-programming]]></category>
            <category><![CDATA[physics]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[automotive]]></category>
            <dc:creator><![CDATA[Rem Voorhuis]]></dc:creator>
            <pubDate>Thu, 23 Jan 2025 22:57:38 GMT</pubDate>
            <atom:updated>2025-01-24T15:28:22.573Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to program realistic vehicle physics for realtime environments / games, Part I: simple suspension and realistic tire dynamics (C++)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LZULtXcCMA-q5na3AmyzoQ.png" /></figure><h3>Table of contents</h3><p>· <a href="#8e26"><strong>Introduction</strong></a><strong><br>· </strong><a href="#2021"><strong>Suspension system</strong></a><strong><br>· </strong><a href="#0b3f"><strong>Tire model</strong></a><strong><br> ∘ </strong><a href="#3139"><strong>MF94</strong></a><strong><br> ∘ </strong><a href="#623d"><strong>MFTire 5.2</strong></a><strong><br> ∘ </strong><a href="#e232"><strong>Other simulatable phenomena</strong></a><strong><br>· </strong><a href="#66f2"><strong>Common problems and solutions with the MF</strong></a><strong><br>· </strong><a href="#01f0"><strong>Conclusion</strong></a></p><h3>Introduction</h3><p>Being a year 2 game programming student at BUas and an avid automotive vehicle and combustion engine fanatic, I’ve always found the topic of vehicle simulation in realtime (for games) fascinating.</p><p>For the average game developer, vehicle simulation is often simplified because the work and effort needed to realistically simulate vehicles is a large task and in the end, not worth it. This is because <strong>1</strong>: easy to access, readable resources are scarce in this area. <strong>2</strong>: you can get away with non-realistic behaviour and still make it look and feel convincing, and <strong>3</strong>: it can be incredibly time consuming to implement stable realistic behaviour of vehicle dynamics.</p><p>If you want to achieve realism though, there is no easy fast way of doing it. That’s why in this article I’d like to share my found knowledge about tire models and their dynamics, and make it easier for you. We will first talk about implementing some simple form of suspension, because it is needed for a vehicle to have realistic weight transfer, which is in turn needed for realistic tire simulation.</p><h3>Suspension system</h3><p>For a simulated vehicle to behave realistically, we always need to have some sort of suspension system in place for it. This stems from the behaviour of vehicles in real life, as suspension is needed to make the ride for the driver comfortable, and to provide better cornering characteristiccs in extreme scenarios. For us it serves another purpose though, and that is that we can easily get the current load on the wheel it’s connected to, which is an important parameter that we need later for a tire model.</p><p>Suspension systems are actually quite complex in real life, being an assembly of multiple mechanical parts like ball joints, struts and/or shocks, control arms, etc. Simulating realistic suspension is therefore a monumental task in itself, and is not something we focus on in this article.</p><p>Instead, we can get away with a spring damper approach. According to Hooke’s law, a spring with damper looks like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*hhLj2k9IsTYsI9ws2EafLA.png" /><figcaption>Where <strong>F </strong>is the force in N, <strong>k </strong>is the stiffness coefficient, <strong>X </strong>is the displacement, <strong>d </strong>is the damper coefficient and <strong>V </strong>is the spring velocity.</figcaption></figure><p>This will calculate a force based on the displacement of the spring, and dampen it based on its velocity. The coefficients are dependent on simulation timestep and vehicle, a good rule of thumb for me is to start with values where <strong>k </strong>is bigger than <strong>d </strong>with a factor of 10. Easy enough right?</p><p>Then, we incorporate this within the simulation having a main vehicle physics body and casting a ray or shape downwards from the origin where the suspension would be attached to the chassis of the car, with a length of the max suspension length (rest length). In the case of raycasting, you’ll typically want to add the wheel radius to that. Depending on what hit info your physics system will spit out, you calculate the the new length (current length) of the suspension. In the case of no hit, we can set the current length to the rest length for now. After that, compute the displacement and get the suspension force via above formula. You add that force to the point on the physics body of the vehicle where the suspension would be attached. Do this 4 times for a 4 wheeled vehicle and you should have some kind of ‘hoverboard’ floating above the ground, and reacting to falls in a realistic manner.</p><p>If you already want to see wheels moving accordingly, you can set their position to the suspension direction * current length of the suspension, dependent of course on how your transform hierarchy is set up.</p><p>We will now move on to the focus of this article: the tire model.</p><h3>Tire model</h3><p>Tire models exist for the sole purpose of modelling realistic phenomena like friction of the rubber tire with the ground. Because rubber is a complex elastic material, the friction is not easily computed.</p><p>There exist numerous tire models, all with different usecases and efficiencies. In this article we will focus on a very well known, cheap to compute and battle tested tire model series; the Pacejka Magic Formulae.</p><p>The Magic Formula (hereby abbreviated to MF) is an empirical formula for describing tire friction forces (<em>Fx, Fy</em>) as a function of slip, and describing the moments (<em>Mx, My, Mz</em>) around the vertical tire axis. Developed initially by the work of <a href="https://en.wikipedia.org/wiki/Hans_B._Pacejka">Hans B. Pacejka</a> and funded by Volvo and Audi VAG, he came up with a series of formulae that describe the output of friction forces of rubber under load and slip. It is empirical, meaning that the coefficients needed as input are obtained by means of <a href="https://en.wikipedia.org/wiki/Curve_fitting#:~:text=Curve%20fitting%20is%20the%20process,points%2C%20possibly%20subject%20to%20constraints."><em>curve-fitting</em></a>. This is the process of getting output data from real-life experiments, and then deriving constants to fit that data with the MF. As such, complete tire data is hard to come by, and usually under corporation ownership and rarely shared.</p><p>The MF is relatively intuitive to use, taking as input parameters the slip quantities for lateral (angle) and longitudinal (ratio) slip. The base MF for friction force is in the form of:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Lqh-SxDGa7eefYH5BOXHg.png" /><figcaption>Where <strong>F </strong>is the output friction force in N, {<strong>D,C,B,E</strong>} are constants acquired from further parameters, and <strong>x </strong>is the slip quantity.</figcaption></figure><p>Where an example c++ implementation looks like</p><pre>float MF52(const MFTireIntermediate&amp; intermediates, float slip)<br>{<br> slip += intermediates.H;<br> return intermediates.D * sinf(intermediates.C * atanf(intermediates.B * slip - intermediates.E * (intermediates.B * slip - atanf(intermediates.B * slip)))) + intermediates.V;<br>}</pre><p>Coefficients <strong>D </strong>(peak factor), <strong>C </strong>(shape factor), <strong>B </strong>(stiffness factor), and <strong>E </strong>(curvature factor) are calculated from a further set of constants that are gained from experimental data, and calculations with them are based on which tire model you use. More about that in the model sub-chapters.</p><p>The aligning moment MF also exists, but is typically omitted since it has nothing to do with tire output forces. The aligning torque is the torque the tire receives around its vertical axis by consequence of wanting to self- align. <strong>However, I will talk about this in the MFTire 5.2 subchapter.</strong></p><p>It will be good to establish SAE correct local coordinate space so terms like Fy and Fx will not be confusing to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*vL6SJjyJZQ1Wdsbtw3_RZw.png" /><figcaption>In this scenario, the tire is experiencing longitudinal (<strong>Fx</strong>) and lateral (<strong>Fy</strong>) friction forces thus a combined friction force (<strong>Fcomb</strong>), an aligning torque (<strong>Mz</strong>) as well as a load / normal force (<strong>Fz</strong>).</figcaption></figure><p>Now we will go over the formulae for the slip quantities needed for the MF, as the MF is a function of slip. There are a lot of slip formulae over the internet, as not all of them are tuned for dynamic scenarios, like games.</p><p>For the longitudinal slip, we can calculate the slip ratio <em>k </em>like so:</p><pre>slip_ratio = (tire.radius * angular_velocity - v_x) / fabs(v_x); </pre><p>Where angular_velocity is the angular velocity of the wheel in rad/s, v_x in m/s, and tire.radius in m.</p><p><em>v_x </em>is the velocity of the tire projected to its longitudinal axis. We can get <em>v_x </em>easily by dotting the point velocity of the contact patch of the tire with the tire’s longitudinal axis. Notice we absolute the value in the denominator to maintain sign flips, as we’d like the slip to be able to be negative (slowing down/braking).</p><p>Since the angular velocity times the radius gives us the tangential (or linear) velocity of the wheel, what <em>k </em>gives us is essentially the ratio of the slip velocity (nominator term) to the actual road velocity beneath the contact patch (denominator term), aka <strong>slip ratio</strong>.</p><p>For the lateral slip, we can compute slip angle <em>a </em>like:</p><pre>slip_angle = -atan2f(lateral_velocity, fabs(wheel.longitudinal_velocity));</pre><p>Where both velocities are in <em>m/s</em>, and slip_angle in <em>rad</em>. lateral_velocity is the velocity of the contact patch projected onto the tire’s lateral axis, similarly computed as the longitudinal velocity. Notice atan2f, because we would like to get the angle in the appropriate quadrant. Also notice the negative, because it works in my left-handed coordinate system. And lastly, notice fabs, as to avoid issues when the longitudinal velocity flips. We’d like the lateral velocity to be the prime determinant of sign flips.</p><p>Now that we have the slip quantities needed for the MF, we can continue to talk about two different MF tire models.</p><h4>MF94</h4><p>I initially found a good resource of the MF from 1994 <a href="https://www.edy.es/dev/docs/pacejka-94-parameters-explained-a-comprehensive-guide/">at a post from a developer that does simulation of vehicles for Unity</a>. This is a good and complete resource where Edy talks about his findings of the MF and describes the parameters needed, as well as the inputs and outputs. The way he’s shown info it is not hard to get something running quickly within your project. He shows usual min-max values and standard forms of the formula, calculations for the intermediate factors {<em>D, C, B, E</em>} and slip quantities calculation. If you want something that is realistic enough and relatively quick to implement I suggest you take a look at his blog post.</p><p>For my project I spent a long time using this model, until I needed a model that could do more, and was not in conflict with <a href="https://www.sae.org/">SAE </a>conventions. You may notice that the input units for the 1994 model described are in percentages, degrees, and load is in <em>kN</em>, which is not standard practice in SAE papers. This is only a problem though if you want to utilize other stuff described in said papers, or if you’re afraid of doing frequent unit conversions. I simply knew of the existence of better tire models, so that also pushed me away from this model.</p><h4>MFTire 5.2</h4><p>Developed by TNO Automotive, it is a successor model to the MF developed in 1994 and onward versions. It aims to be a relatively fast to compute model and is all-encompassing, meaning it can handle and perform well under a wide if not all types of scenarios. There exist complexity levels in the model, depending on the realism you need.</p><p>If you are still here, you probably want to know more about this model’s way of attaining the coefficients needed for using the MF. To be exact, <strong>D, C, B, </strong>and <strong>E. </strong>Whats nice is<strong> </strong>both<strong> </strong>lateral and longitudinal force<strong> </strong>versions of the MF simplify down to a couple of constants. Thus, we can make a MFTireIntermediate struct that contains them:</p><pre>struct MFTireIntermediate<br>{<br> //shape factor<br> float C;<br> <br> //peak value<br> float D;<br><br> //peak value factor <br> float mu;<br><br> //curvature factor<br> float E;<br><br> //slip stiffness (BCD), or cornering stiffness<br> float K;<br><br> //stiffness factor<br> float B;<br><br> //horizontal shift<br> float H;<br><br> //vertical shift<br> float V;<br>};</pre><p>How we calculate these exactly, is different for either version though. As mentioned previously, these intermediates are derived from more constants. For the longitudinal, we count 15 in total:</p><pre>struct MFTireLongitudinal<br>{<br> //shape factor <br> float Cx1;<br><br> //longitudinal friction at Fz nominal<br> float Dx1;<br><br> //variation of friction with load<br> float Dx2;<br><br> //variation of friction with camber<br> float Dx3;<br><br> //longitudinal curvature at Fz nominal<br> float Ex1;<br><br> //variation of curvature with load<br> float Ex2;<br><br> //variation of curvature with load squared<br> float Ex3;<br><br> //factor in curvature while driving<br> float Ex4;<br><br> //longitudinal slip stiffness at fz nominal<br> float Kx1;<br><br> //variation of slip stiffness with load<br> float Kx2;<br><br> //exponent in slip stiffness with load<br> float Kx3;<br><br> //horizontal shift at fz nominal<br> float Hx1;<br><br> //variation of shift with load<br> float Hx2;<br><br> //vertical shift at fznom<br> float Vx1;<br><br> //variation of shift with load<br> float Vx2;<br>};</pre><p>For the lateral inputs, we count a total of 18 parameters:</p><pre>struct MFTireLateral<br>{<br> //shape factor <br> float Cy1;<br><br> //lateral friction at Fz nominal<br> float Dy1;<br><br> //variation of friction with load<br> float Dy2;<br><br> //variation of friction with camber squared<br> float Dy3;<br><br> //lateral curvature at Fz nominal<br> float Ey1;<br><br> //variation of curvature with load<br> float Ey2;<br><br> //zero order camber dependency of curvature<br> float Ey3;<br><br> //variation in curvature with camber<br> float Ey4;<br><br> //maximum value of stiffness fy with fz nom<br> float Ky1;<br><br> //load at which kfy reaches maximum value<br> float Ky2;<br><br> //variation of kfy/fznom with camber<br> float Ky3;<br><br> //horizontal shift at fz nominal<br> float Hy1;<br><br> //variation of shift with load<br> float Hy2;<br><br> //variation of shift with camber<br> float Hy3;<br><br> //vertical shift at fznom<br> float Vy1;<br><br> //variation of shift with load<br> float Vy2;<br><br> //variation of shift with camber <br> float Vy3;<br><br> //variation of shift with camber and load<br> float Vy4;<br>};</pre><p>These are the constants gained from curve-fitting data from real-life experiments. Maybe the hardest part about this is that you need to find complete and compatible MFTire 5.2 data sets. No worries though, I’ll set you up with a couple of complete resources:</p><p><a href="https://github.com/modelica-3rdparty/ExternData/blob/master/ExternData/Resources/Examples/sample.tir">Sample.tir from modelica</a></p><p><a href="https://github.com/OpenTire/OpenTirePython/blob/master/code/opentire/TireModel/PAC2002/PAC2002.py">PAC2002 coefficients from OpenTire</a></p><p>These have all the coefficients needed for MF5.2, if not more (Sample.tir even has coefficients for MF6.2).</p><p>Moving on to the calculations to the longitudinal intermediates with these constants:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*G_F2VouRtoY_JGLoaPGhOQ.png" /></figure><p>I’ll save you the writing for c++:</p><pre>MFTireIntermediate GetMFTireIntermediate(const MFTireLongitudinal&amp; params, const MFTireScaleParams&amp; scaling, MFTireState state)<br>{<br> MFTireIntermediate long_intermediates;<br><br> //Yx = y * mu y<br> state.camber *= scaling.l_camber;<br><br> //Shx<br> long_intermediates.H = (params.Hx1 + params.Hx2 * state.normalized_load_increment) * scaling.l_horizontal_shift;<br><br> //Kx = k + Shx<br> state.slip_ratio += long_intermediates.H;<br><br><br> long_intermediates.C = params.Cx1*scaling.l_shape_factor;<br><br> long_intermediates.mu = (params.Dx1 + params.Dx2*state.normalized_load_increment) * (1.f - params.Dx3 * (state.camber*state.camber)) * <br>        scaling.l_peak_friction_coefficient;<br><br> long_intermediates.D = long_intermediates.mu * state.fz;<br><br> long_intermediates.E = (params.Ex1 + params.Ex2 * state.normalized_load_increment + params.Ex3*(state.normalized_load_increment*state.normalized_load_increment)) * <br>       (1.f - params.Ex4*sign(state.slip_ratio)) * scaling.l_curvature_factor;<br><br> long_intermediates.K = state.fz * (params.Kx1 + params.Kx2 * state.normalized_load_increment) * glm::exp(params.Kx3*state.normalized_load_increment) * <br>       scaling.l_slip_stiffness;<br><br> long_intermediates.B = long_intermediates.K / (long_intermediates.C * long_intermediates.D);<br><br> long_intermediates.V = state.fz * (params.Vx1 + params.Vx2*state.normalized_load_increment) * scaling.l_vertical_shift * scaling.l_peak_friction_coefficient;<br><br> return long_intermediates;<br>}</pre><p>For the lateral intermediates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*WgNRo45YI-DJ1DjvWKjELg.png" /></figure><p>Again, I’ll save you the effort:</p><pre>MFTireIntermediate GetMFTireIntermediate(const MFTireLateral&amp; params, const MFTireScaleParams&amp; scaling, MFTireState state)<br>{<br> MFTireIntermediate lat_intermediates;<br><br> state.camber *= scaling.l_camber;<br><br> //Shy<br> lat_intermediates.H = (params.Hy1 + params.Hy2*state.normalized_load_increment) * scaling.l_horizontal_shift + params.Hy3 * state.camber;<br><br> //alphay = alpha + Shy<br> state.slip_angle += lat_intermediates.H;<br><br> lat_intermediates.C = params.Cy1 * scaling.l_shape_factor;<br><br> lat_intermediates.mu = (params.Dy1 + params.Dy2 * state.normalized_load_increment) * (1.f - params.Dy3 * (state.camber*state.camber)) * scaling.l_peak_friction_coefficient;<br><br> lat_intermediates.D = lat_intermediates.mu * state.fz;<br><br> lat_intermediates.E = (params.Ey1 + params.Ey2 * state.normalized_load_increment) * (1.f - (params.Ey3 + params.Ey4 * state.camber) * sign(state.slip_angle)) *<br>       scaling.l_curvature_factor;<br><br> lat_intermediates.K = params.Ky1 * nominal_load * sinf(2.f*atanf(state.fz / (params.Ky2 * nominal_load * scaling.l_nominal_load) )) *<br>            (1.f - params.Ky3 * fabs(state.camber)) * scaling.l_nominal_load * scaling.l_slip_stiffness;<br><br> lat_intermediates.K *= -1.f;<br><br> lat_intermediates.B = lat_intermediates.K / (lat_intermediates.C * lat_intermediates.D);<br><br> lat_intermediates.V = state.fz * ((params.Vy1 + params.Vy2 * state.normalized_load_increment) * scaling.l_vertical_shift + (params.Vy3 + params.Vy4 * state.normalized_load_increment)<br>            * state.camber) * scaling.l_peak_friction_coefficient;<br><br> return lat_intermediates;<br>}</pre><p>One can notice the MFTireScaleParams and MFTireState inputs alongside the the input arguments, the former is just a container with scale coefficients, and the latter is the current state of the tire. We’ll go over them, starting with the scaling factors:</p><pre>struct MFTireScaleParams<br>{<br> //scale factor of the C shape factor<br> float l_shape_factor = 1.f;<br> <br> //scale factor of either long or lat peak friction coefficient<br> float l_peak_friction_coefficient = 1.f;<br><br> //scale factor of E curvature factor (&lt;= 1)<br> float l_curvature_factor = 1.f;<br><br> //scale factor of either long (slip) or lat (cornering) stiffness<br> float l_slip_stiffness = 1.f;<br><br> //scale factor of horizontal shift<br> float l_horizontal_shift = 1.f;<br><br> //scale factor of vertical shift<br> float l_vertical_shift = 1.f;<br><br> //scale factor of camber for either long or lat force<br> float l_camber = 1.f;<br><br> //scale factor of nominal (rated) load<br> float l_nominal_load = 1.f;<br>};</pre><p>As described by the papers these are the same for longitudinal and lateral, meaning it can be used interchangeably. They provide easy tuning capabilities without drastically affecting the dataset and the model.</p><p>Secondly, the tire state struct is a container for the state the tire is in. It contains all variables that could possibly change and affect the tire’s behaviour:</p><pre>struct MFTireState<br>{<br> //N<br> float fz;<br> //dfz<br> float normalized_load_increment;<br> //rad<br> float camber;<br> //rad<br> float slip_angle;<br> //scalar<br> float slip_ratio;<br> //effective rolling radius<br> float radius_effective;<br>};</pre><p>I will explain all these now. <em>Fz </em>is a recurring parameter, it is the load/normal force the tire delivers back to the chassis in N. We set up the suspension specifically for this reason, so that we can get <em>Fz </em>easily. As we know from Newtons third law, we can state:</p><pre>//equal and opposite reaction<br>wheel.tire_state.fz = force + wheel_self_fz;</pre><p><em>force </em>being the suspension output force, and <em>wheel_self_fz</em> the normal force of the tire alone (depending on if it’s grounded or not).</p><p>The normalized load increment factor (<em>dFz</em>) can also be seen in the calculations for the intermediates. In the papers, its defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*kqYDyBkyj59-WzXDpmvRWA.png" /><figcaption>Where <strong>Fz</strong> is the vertical load, and <strong>F’z0</strong> is the possibly adapted nominal load</figcaption></figure><p>The possibly adapted nominal load is a scaled nominal load. The nominal load is the rated load at which the tire model is tested, and usually a constant. They can be found in linked datasets. The possibly adapted nominal load is a scaled rated load that is an approximation for different loads, given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*HAUioLV_HJbyeL3zh4mj7A.png" /><figcaption>Fz0 is the rated nominal load, and the lambda is a user scaling factor</figcaption></figure><p>The scaling factor I roughly determine by getting the vehicle total mass, spreading it out over its total wheels, and dividing that load (in N) over the rated nominal load to get the lambda.</p><p>Then, camber angle is there because it could vary with advanced suspension simulation. It at least belongs together with slip ratio and slip angle, which are the main inputs to the model, already described above.</p><p>There is another thing though, called the effective radius. Because a tire is not a solid object but rather a stiff cushion deforming under load on the road, the effective radius can vary under different load conditions. It can be computed by employing another MF:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*lx84ihsRUal40VpAQkl5lg.png" /><figcaption>Where <strong>R0</strong> is the unloaded radius, <strong>Pfz0</strong> the nominal tire deflection, <strong>pd </strong>the dimensionless radial tire deflection<strong> </strong>and coefficients <strong>B,D</strong> and <strong>F </strong>constants gained from datasets. The paper approximates for a passenger car: <strong>B </strong>= 8.4, <strong>D</strong> = 0.27 and <strong>F </strong>= 0.045.</figcaption></figure><p>The nominal tire deflection is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*nX9RNVAeGftalS0hxpLUeg.png" /><figcaption>Where <strong>Cz</strong> is the vertical tire stiffness in N/mm (I employ a range of 100–250)</figcaption></figure><p>The dimensionless radial tire deflection is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/139/1*hnmr3Q3RAsnyoNgfvKugqw.png" /><figcaption>Where <strong>Pfz0</strong> is the nominal tire deflection, and <strong>p </strong>the radial tire deflection</figcaption></figure><p>The radial tire deflection is calculated as such:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/211/1*UGLETcsHNFVik0ERAoPOJg.png" /><figcaption>With <strong>Cz </strong>the vertical stiffness (N/mm) and <strong>Fz </strong>the load (N).</figcaption></figure><p>To make the effective radius somewhat stable and not induce a feedback loop, the paper employs a better calculation for <strong>Fz</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*vglStBMeJI6DkhRK7l4Otw.png" /><figcaption>With <strong>Cz </strong>the vertical tire stiffness (N/mm), <strong>p </strong>the radial tire deflection, <strong>Kz </strong>the vertical dampening coefficient, and <strong>p_deriv</strong> the velocity of the deflection.</figcaption></figure><p>As you may notice there is a damper term introduced. Also, <em>Cz * p</em> simplifies to just input <em>Fz </em>from our suspension, as deflection <em>p </em>is <em>Fz</em>/<em>Cz</em>.</p><p>In the end, graphing this effective rolling radius <em>Re, </em>we can see the radius decrease sharply then fall off with increasing load:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*yOaFJH5_NbmaU-IH4dJgdA.png" /></figure><p>As always, yours truly will save you time by providing an example implementation:</p><pre>float GetEffectiveRollingRadius(const MFTireRubberParams&amp; tire_params, float fz)<br>{<br> //TODO: optimize<br><br> //nominal tire deflection (mm)<br> float nominal_tire_deflection = nominal_load / tire_params.C_z;<br><br> //current tire deflection (mm)<br> float tire_deflection = fz / tire_params.C_z;<br><br> //dimensionless radial tire deflection<br> float tire_deflection_d = tire_deflection / nominal_tire_deflection;<br><br> //magic formula for effective rolling radius under load, MFTyre (4)<br> return tire_params.R_0 - (nominal_tire_deflection*0.001f) * (tire_params.D*atanf(tire_params.B*tire_deflection_d) + tire_params.F*tire_deflection_d);<br>}</pre><p>Notice how I had to introduce a unit conversion from <em>mm </em>to <em>m </em>for nominal tire deflection to make sense. In the paper this is not obvious, and I’m not sure this is a mistake or not. Anyways, results are a match for the results obtained in the paper.</p><p>Aside from the base MF being the same as the one mentioned at the start of the chapter, MFTire has MF’s for aligning torque. Aligning moments (<em>M</em>) are the moments that make the tire want to self-align when the its true heading is different than its current longitudinal direction, basically when there is positive slip angle |<em>a|</em>. When you provide input to the steering wheel, you feel feedback force (or rather torque) from this aligning torque around the vertical axis of the tire propagating back through the steering rack to the steering wheel.</p><p>The formula for aligning torque is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*7s6Xx3J_KsIBgg78Ds8-mw.png" /><figcaption>Where <strong>Mz </strong>is the aligning torque, <strong>t</strong> is the pneumatic trail, <strong>Fy </strong>is the lateral force and <strong>Mzr</strong> is the residual torque.</figcaption></figure><p>The pneumatic trail <em>t </em>is given by a cosine version of the MF:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*GGzB-7y5OHjQKOkfOY1ZLw.png" /><figcaption>Where <strong>D,C,B,E</strong> are constants gained from intermediate factor computation, <strong>a </strong>the slip angle (rad) and <strong>a_t</strong> the horizontally adjusted slip angle.</figcaption></figure><p>The residual torque <em>Mzr </em>is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*_5gVlssIX7X350qyUvHW1Q.png" /><figcaption>Where D and B are intermediate constants gained further computation, <strong>a </strong>is the slip angle (rad) and <strong>ar </strong>is the horizontally adjusted slip angle.</figcaption></figure><p>I won’t focus further on aligning moments as they are not the focus of this article, and you’ll hardly need them unless you want realistic force feedback and a physically simulated vertical axis.</p><h4>Other simulatable phenomena</h4><p>The model can simulate other interesting phenomena that come into play with rubber and rotating motion. More simulation fidelity can be gained by implementing these phenomena.</p><ol><li><strong>The rubber rolling resistance</strong></li></ol><p>When a tire rotates over the ground, rubber will actually compress slightly before the center of the contact patch, and decompress when a far enough distance has been traveled relative to the contact patch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*8IefzzS5dVdXE_rO89qKLQ.png" /></figure><p>This results in energy loss, described by the rolling resistance moment (<em>My</em>) MF:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*HvYHHN1aJQOHvN4I8jbyLw.png" /><figcaption>Where <strong>R0 </strong>is the unloaded radius (m), <strong>Fz </strong>the load (N), <strong>qsy1,2,3,4</strong> all constants gained by dataset, <strong>Vx </strong>the longitudinal velocity (m/s), and <strong>Vref </strong>the rated longitudinal velocity at which the tire was tested.</figcaption></figure><p><em>Vref </em>is usually found alongside the dataset.</p><p>2. <strong>Transient response</strong></p><p>A rubber tire does not respond to changes immediately, it rather lags behind the changes in state for slip just a little. This has to do with the tire contact patch sticking to the ground with its state of velocity due to the elasticity of rubber not directly adhering to new wheel hub changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*u0ZXQxHzFmbhm0AOcR8JOQ.png" /><figcaption>Source: TNO MFTire presentatie</figcaption></figure><p>MFTire is able to model transient phenomena quite well, with different models like carcass stiffness and contact patch transient forces. However, at the time of writing I have not implemented and researched this topic enough to talk about it comfortably. When I do though, I will update the article accordingly.</p><p>3.<strong> Gyroscopic couple</strong></p><p>The gyroscopic couple is an interesting effect that occurs when the wheel starts rotating quickly enough that it becomes a gyroscope and resists motion along its vertical axis, to be felt along the other aligning moments. The MF for this torque can be calculated by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*cexhtSPmSr-VtsCr3pTwgw.png" /><figcaption>Where <strong>cgyr </strong>is calculated by a scaling factor and a constant from dataset, <strong>mbelt </strong>the mass of the belt, <strong>Vrl </strong>the relative velocity.</figcaption></figure><p><em>Cgyr </em>is calculated as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*FK8I4jn2BggPXQIj1tFRNQ.png" /><figcaption>Where <strong>qTzl </strong>is the gyroscopic torque constant, and the lambda a scaling factor</figcaption></figure><p>4. <strong>Enveloping tire functionality</strong></p><p>Because a tire is made of rubber, it can deform around very small obstacles, aka envelop them. When one has a rigid tire, this behaviour is not possible. So MFTire has the capability to simulate an enveloping tire model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*upYDAYP0MrFo0ocZYpUNFQ.png" /><figcaption>I’m not sure if you still have to do transient phenomena if you implement enveloping behaviour, as it seems you’re already lengthening response time! Source: TNO MFTire presentatie</figcaption></figure><p>To simulate this complex behaviour, MFTire supplies us with a double cam enveloping model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*6S8_9RDFMpM_R__nH71KQw.png" /><figcaption>Source: TNO MFTire presentatie</figcaption></figure><p>Obviously this is more leaning into the actual simulation side of tires, but it’s still very interesting to see such a tire model get gradually more complex. I’m not going to focus much more on this though, as I don’t think its useful enough to implement immediately. Only when the simulation fidelity is needed on this level, should you consider implementing such a model.</p><h3>Common problems and solutions with the MF</h3><p>The magic formulae are great, but it exists not without its flaws. There are some crucial problems with it that one needs to solve when using them. I will go over them and how I solved them below. Most of the papers described below are behind a paywall, but I will link the DOI, and a clever individual will know ways with certain sites to access the paper freely with the DOI.</p><ol><li><strong>Singularity at zero speed</strong>: The slip quantity inputs to the magic formulae have the longitudinal velocity of the tire in their denominator. Thus, when the vehicle speed approaches zero, the outputs will become numerically unstable and approaches singularity. Luckily this is a common problem in vehicle simulation, and multiple papers have proposed solutions to solve this problem.</li></ol><p>Some papers that propose solutions (in ascending publication date order):</p><p>LSR (Lagged slip ratio, by Bernard and Clover) approaches this problem by integrating the slip ratio in a differential equation instead of computing it as is. DOI: <a href="https://doi.org/10.4271/950311">10.4271/950311</a></p><p>ASR (Advanced slip ratio, by Jung et al.) approaches this problem by analyzing the instability and ensuring convergence to a numerically stable result. DOI: <a href="https://doi.org/10.1177/0954407018759738">10.1177/0954407018759738</a></p><p>ALSR (Advanced lagged slip ratio, by Jung et al.) approaches this problem by combining lagged and advanced slip ratio to ensure stability at low and high speed vehicle simulation. DOI: 10.1007/s12206–020–0110-y</p><p>After implementing one or multiple of these solutions to the problem, you can test them and see their effect. These solutions are crucial to achieve low-speed driving stability for realistic behaviour.</p><p>2. <strong>Lateral friction does not scale with lateral velocity</strong></p><p>As seen in the slip quantity calculations, for the slip ratio we calculate the longitudinal slip speed (the difference in linear velocities of tire and heading) and use it to measure against just the longitudinal velocity. This gives us a ratio that measures how fast the tire is spinning relative to the ground. The slip ratio is thus already taking into account the velocity of the slip for its longitudinal force. For the slip angle, we still use velocity component <em>Vsy</em>, which is the lateral slip velocity of the contact patch. But, we divide it by the longitudinal velocity to get the input to the arc tangent that computes the angle between the tire true heading and the tire’s direction. We don’t use it to get a ratio of how fast the lateral slip speed is.</p><p>This slip angle does not take into account lateral velocity experienced by the tire. Moreover, at low speed the absolute slip angle will be around an angle of +-90 degrees because of the low longitudinal velocity. This generates significant lateral forces, continuously oscillating the vehicle in lateral tire direction at standstill while this is not even needed. We can better make use of the longitudinal force to keep the vehicle still as a larger lateral force will cut down the longitudinal force by some amount.</p><p>How I solved this is using only the lateral force when it is necessary:</p><pre>   wheel.lateral_slip_factor = fmin(fabs(lateral_velocity*3.f) + fabs(wheel.steering_angle)/vehicle.max_steering_angle, 1.f);</pre><p>Effectively I use a scaling factor to scale <em>fx </em>by. The scaling factor depends on the lateral velocity multiplied by 3, as that seems to increase the wanted responsiveness enough and not use all lateral force capability at standstill. It also works for my unit size. I also add a dependency for the steering angle, as we’d like to instantly notice new heading of the tire being in effect, instead of waiting until the lateral velocity is big enough.</p><p>3. <strong>Either lateral or longitudinal formula is true when the other is not.</strong></p><p>The lateral MF <em>Fx</em>(<em>a</em>) output is only true when the MF for longitudinal force <em>Fy</em>(<em>k</em>) = 0, and vice versa. As such, we need a way to combine the two forces into a combined slip force as a tire can only output so much friction force. You can think of this as normalizing the forces into a force vector. because the lateral and longitudinal forces magnitude stem from the load directly, they only are true for that entire range and when the adversary force = 0. Otherwise a tire could put out +-8000N at peak slip at a load of 4000N.</p><p>A number of techniques exist to get the combined slip from the magic formulae, and I’ll detail on 4 of them.</p><p><strong>Technique 1</strong>: I’ve seen implementations where the longitudinal force (Fx) gets favored over the lateral force (Fy) and the lateral force gets cut down until the magnitude of the force vector is the maximum again. This simple solution is a quick way to stably test other crucial stability dynamics of the model, but is not forgiving in scenarios where the tire experiences meaningful lateral and longitudinal slip. Since Fy will get cut down in favor of Fx, the car will either heavily understeer or oversteer, depending on drivetrain configuration.</p><p><strong>Technique 2</strong>: <a href="https://www.miata.net/sport/Physics/Part21.html">In The physics of racing by Brian Beckman</a>, an awesome resource for physics dynamics of vehicles, on combined slip he firstly notes:</p><blockquote>“There are a lot of ways we could stitch them together. This is not the kind of situation where there is one right answer. Instead, in the absence of hard theory or experimental data, we have the freedom to be creative, with the inevitable risk of being wrong. We pick a method that satisfies some simple, intuitive, physical requirements.”</blockquote><p>Which is a nice way of saying that the following is not an absolute “right” approach and that it should not be taken as ground-truth, but rather a logical approach to the problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*G14h_htgatrSVvTgln9Hsw.png" /></figure><p>As seen above, Brian takes the approach of scaling the the inputs by a factor of the peak grip circle. He first computes the maxima of <em>Fx </em>and <em>Fy</em>, which is already problematic since it requires a derivative of the magic formula at a certain load, and since load-dependent factors exist in the newer tire model calculating the derivative each tick is a large task in itself. He then uses those maxima to get a ratio of the current against the maxima, getting a dimensionless <em>s</em> and <em>a</em> slip quantity ratio. He then normalizes them into maximum <em>p</em>, which he then uses to scale normal <em>Fx</em> and <em>Fy </em>by according <em>s</em> and <em>a</em>. This essentially gets us a friction circle forces around the maximum slip.</p><p><strong>Technique 3</strong>: MFTire 5.2 has another set of empirical magic formula weighting functions with curve-fitted constants that cut down pure <em>Fx</em> and <em>Fy </em>respectively. These weighting functions are MFs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*HKo8f37CXkiZqH3CKU1Viw.png" /><figcaption>Where <strong>Fx0 </strong>the pure longitudinal friction, <strong>Gxa </strong>the weighting function</figcaption></figure><p>Where the weighting function <em>Gxa </em>is computed as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*YyQ8gcwHSaFqXypObuhOMg.png" /><figcaption>Where <strong>as </strong>is the horizontally shifted slip angle, <strong>Cxa, Bxa, Exa, Shxa </strong>are constants computed by further dataset constants</figcaption></figure><p>Horizontally shifted slip angle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*NQMKvO1nD5dfqF5oh27z-g.png" /></figure><p>The retrieval of <em>Cxa, Bxa, Exa, </em>and <em>Shxa</em> is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*-MxZ489oLu1s69R6NSJvWQ.png" /><figcaption>Where <strong>rBx1, rBx2, rCx1, rEx1, rEx2, rHx1</strong> are all dataset constants, <strong>dfz </strong>the normalized load increment, <strong>k </strong>the slip ratio, and the lambda a scaling factor. Notice <strong>Dxa</strong>, in the paper it appears to explain derivation to the weighting function.</figcaption></figure><p>The lateral combined slip calculation is similar, I’ll quickly paste them down for you:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*kNt-eF1J3_sEj7eqiqrU4g.png" /></figure><p>With weighting function <em>Gyk</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*GFAR9kTGJBqcqIS81b5CPw.png" /></figure><p>And coefficient computation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*hYG4EJhQHvm37uIMr63UoA.png" /><figcaption>with new appearing <strong>y </strong>as camber angle (rad).</figcaption></figure><p>I have not yet implemented this form of combined slip, so I cannot provide code for this method yet.</p><p><strong>Technique 4:</strong> There are tens of other techniques to combine slip forces, but another interesting one I found was on the website of ADAMs/Tire, an industry standard vehicle simulation software. They have explanations about 89 and 94 models of pacejka, with an <a href="https://nexus.hexagon.com/documentationcenter/en-US/bundle/adams_2022.1/page/adams_help/Adams_Car_Package/tire/tire_models_pacgeneric/TOC.Combined.Slip.of.Pacejka.xhtml">in-house way of combining slip forces</a>. Quoted from their website:</p><blockquote>”The combined slip calculation of the Pacejka ’89 and ’94 tire models is identical. Note that the method employed here is not part of the Magic Formula as developed by Professor Pacejka, but is an in-house development of MSC.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*isD42b4_Cc-xckLroFAhtQ.png" /></figure><p>Where the calculation of beta:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*i_aPDodlFBUOtEquhmvJ9A.png" /><figcaption>where <strong>k </strong>is slip ratio, <strong>a </strong>is slip angle (rad).</figcaption></figure><p>For this one, I have a complete c++ implementation for you:</p><pre>glm::vec2 GetCombinedSlipMSC(float fx, float fy, float fz, float slip_ratio, float slip_angle, const MFTireIntermediate&amp; long_factors, const MFTireIntermediate&amp; lat_factors)<br>{<br> //In house implementation of MSC, ADAMs/tire<br> //https://nexus.hexagon.com/documentationcenter/en-US/bundle/adams_2022.1/page/adams_help/Adams_Car_Package/tire/tire_models_pacgeneric/TOC.Combined.Slip.of.Pacejka.xhtml<br><br> float a_slip_ratio = slip_ratio + long_factors.H;<br> float a_slip_angle = slip_angle + lat_factors.H;<br><br> float SAG = sinf(a_slip_angle);<br><br> float SAG_sqr = SAG * SAG;<br> float a_slip_ratio_sqr = a_slip_ratio * a_slip_ratio;<br><br> float beta = acosf(fabs(a_slip_ratio) / (sqrtf(a_slip_ratio_sqr + SAG_sqr) + FLT_EPSILON));<br><br> //calc friction coefficients<br><br> //actual longitudinal coeff<br> float mu_x_act = (fabs(fx - long_factors.V) / (fz + FLT_EPSILON)) + FLT_EPSILON;<br> //actual lateral coeff<br> float mu_y_act = (fabs(fy - lat_factors.V) / (fz + FLT_EPSILON)) + FLT_EPSILON;<br><br> //maximum coeffs<br> float mu_x_max = (long_factors.D / (fz + FLT_EPSILON)) + FLT_EPSILON;<br> float mu_y_max = (lat_factors.D / (fz + FLT_EPSILON)) + FLT_EPSILON;<br><br> //now calculate the friction mu&#39;s<br> float mu_x = 1.f / sqrtf((1.f / mu_x_act) * (1.f / mu_x_act) + (tanf(beta) / mu_y_max) * (tanf(beta) / mu_y_max));<br> float mu_y = tanf(beta) / sqrtf((1.f / mu_x_max) * (1.f / mu_x_max) + (tanf(beta) / mu_y_act) * (tanf(beta) / mu_y_act));<br><br> float fx_combined = (mu_x / mu_x_act) * (fx + long_factors.V);<br> float fy_combined = (mu_y / mu_y_act) * (fy + lat_factors.V);<br><br> return glm::vec2(fx_combined, fy_combined);<br>}</pre><p>As seen above, the method they use is similar to the scaling factor method also employed in <strong>technique 2</strong>. we calculate μ actual and μ maximum for either part of the force, then calculate the final μ friction coefficient to scale with μ max to get a scalar 0–1, then use that to cut down pure friction force <em>Fx </em>and <em>Fy</em>. What is cool about this method its relatively easy to implement and takes into account the slip quantities to derive final forces.</p><p>In the end though, you test a lot of techniques and see which one is best for your type of game.</p><h3>Conclusion</h3><p>I think we talked enough about tire models and their specifics, as it’s become quite a lengthy article. The goal of this article is wanting to share as much knowledge with you, reader, so that you can save yourself the time I spent finding and researching this information. If a part II ever comes out, we will talk about simulating internal combustion engine dynamics, and drivetrain simulation.</p><p>I hope you enjoyed reading, and if you have questions or notice any inconsistencies, be sure to let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4c2375dc7fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>