Decelerate a spinning wheel over a specific time and specific distance

Started by
2 comments, last by phlp 2 years, 5 months ago

Example problem:

Decelerate a wheel from 360 degrees per second to a speed of 0 over 2.5 seconds and have the wheel rotate for 234 degrees.

The example code below doesn't use a specific time as a variable in the wheel deceleration, but the wheel will travel and slow down over the specified degrees:

I have a wheel rotating at its spinSpeed. I have calculated how many more degrees for it to rotate for, called degreesOfDeceleration and it should decelerate as it spins through these final degrees. curDegree starts at degreesOfDeceleration and goes to 0.

float speed = spinSpeed * (curDegree / degreesOfDeceleration);

float rotationDelta = speed * Time.deltaTime;

curDegree -= rotationDelta;

transform.eulerAngles = new Vector3(0.0f, 0.0f, transform.eulerAngles.z + rotationDelta);

if (curDegree <= 0.0f ) StoppedSpinningWheel();

What is missing from this example is how to force the spin to finish within a specific time. I'm not sure how.

Advertisement

If you want constant acceleration (like you do now), then you can consider it as identical to the second equation of motion from basic physics:

$$s = s_0 + v_0 t + \frac{1}{2} a t^2s$$

only with s as an angle, v as your angular velocity. Solve for a. This probably won't give you what you want, i.e. your final velocity won't be 0.

Let's say, then, that our acceleration is linear, i.e.

$$a(t) = mt + b$$

Then our velocity is necessarily quadratic

$$v(t) = \frac{m}{2} t^2 + bt + c$$

with the constant term dictated by the intial velocity

$$v(0) = 360 = c$$

and position given by the definite integral

$$s(2.5) = \int_{0}^{2.5} v(t) dt = \frac{m}{6} (2.5)^3 + \frac{b}{2} (2.5)^2 + 360(2.5)$$

so with the distance traveled and other constraints we have the other equation

$$v(2.5) = \frac{m}{2} (2.5)^2 + b (2.5) + 360 = 0$$

So you have two equations and two unknowns. Just solve for m and b and plug those into a=mt+b.

My itch.io page, just game jams so far

Editing posts destroys equations, so I'll just sum up here instead:

$$\frac{m}{6} (2.5)^3 + \frac{b}{2} (2.5)^2 + 360(2.5) = 234$$

$$\frac{m}{2} (2.5)^2 + b (2.5) + 360 = 0$$

are your two equations, and your acceleration will be

$$ a = m t + b$$

with m and b solved from above

My itch.io page, just game jams so far

This topic is closed to new replies.

Advertisement