Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A better model for friction is that the frictional force is proportional to velocity. You'll need a constant to determine the relationship between force and acceleration (mass, more or less). Writing the relationships as a difference equation,</p> <pre><code>F[n] = -gamma * v[n-1] a[n] = F[n]/m v[n] = v[n-1] + dt * a[n] = v[n-1] + dt * F[n] / m = v[n-1] - dt * gamma * v[n-1] / m = v[n-1] * (1 - dt*gamma/m) </code></pre> <p>So, if you want your deceleration to look smooth and natural, instead of linearly decreasing your velocity you want to pick some constant slightly less than 1 and repeatedly multiply the velocity by this constant. Of course, this only asymptotically approaches zero, so you probably want to have a threshold below which you just set velocity to zero.</p> <p>So, for example:</p> <pre><code>v_epsilon = &lt;some minimum velocity&gt;; k_frict = 0.9; // play around with this a bit while (v &gt; v_epsilon) { v = v * k_frict; usleep(1000); } v = 0; </code></pre> <p>I think you'll find this looks much more natural.</p> <p>If you want to approximate this with a linear speed reduction, then you'll want to make the amount of time you spend slowing down proportional to the natural log of the initial velocity. This won't look quite right, but it'll look somewhat better than what you've got now.</p> <p>(Why natural log? Because frictional force proportional to velocity sets up a first-order differential equation, which gives an exp(-t/tau) kind of response, where tau is a characteristic of the system. The time to decay from an arbitrary velocity to a given limit is proportional to ln(v_init) in a system like this.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload