Saturday, April 21, 2012

Movimentum - Design of the language - Calculus

Let us now apply the brakes to our pump: It should stop, but not abruptly, but rather slowly slide to a standstill. Instead of thinking about a formula for the angular velocity, I'd like to use simple integrals:

@+08.0   b = -180 / 6; // angular acceleration

180 is the current angular velocity (in °/s). We want the crank to stop after 6 seconds - therefore, the angular acceleration is 180/6, and it is negative because the angular velocity should decrease. In standard physics, integrating this value over t will yield the required changing angular velocity. So I want to write (w should be pronounced "omega" here ;) ):

         w = integral(b);

The integral is implicitly over a variable τ, and its integration range is from 0 to t. However, w has to start at is current value, so we have to add 180:

         w = integral(b) + 180;

(I suspect that instead of the constant 180, in more complex scenarios it is necessary to get the current value from the model - e.g., if an accelerating object has to brake down again in the middle of the acceleration. But I'll think about this later.) The slowing movement now can be described as

         Crank.Q = Crank.P + [_,0].rotate(w * t);

There is a small problem with this: If we do not stop this segment after exactly 6 seconds, the crank will start to rotate backwards. And even if we do this, we'll have rounding errors in the real implementation. Hence, it is probably useful to add

@+06.0   w = 0;


No comments:

Post a Comment