# Calculating speed and reversing inertia

• SeanCocteau
In summary, the conversation is about a programmer seeking help with calculating the final position of an object in an animation sequence. The issue is that the object needs to slow down and stop at a specific position, but the programmer is having trouble determining the expected distance and using the correct formula to adjust the speed. Suggestions are made to use a non-linear formula for acceleration or to adjust the acceleration coefficient based on the velocity of the object at each time interval.
SeanCocteau
Hi

I'm a programmer and while my maths is OK, my understanding of physics is not the best so apologies in advance if I'm missing something obvious. My problem is an interaction and animation sequence I'm writing, the user can swipe an object from one position to another. No problem here. The issue is that I need the object to 'dock' to a specific position, again no problem calculating the final resting position.

My problem is that I applying inertia (I decrement the detected speed on each animation cycle so this value is undeterminent) causing the object to slow and then stop once it hits a specific figure. Originally I thought I could calculate the 'expected distance' the object would travel to, but I believe that I did not have enough parameters to do this, only the speed and deceleration value. To calculate the expected distance, I create a second loop, decrement the speed but adding to the expected distance until it hits the stop speed. Not overly elegant, but it returns the correct figure.

However, to get the object to end at a specific position I need to reverse this calculation, adjusting the speed of the object so it lands in the appropriate position. At the moment, I've been using Vf^2 = Vi^2 + 2ad but this hasn't been providing the correct values so far.

For instance, the speed is 38 pixels per animation frame, the initial starting velocity is 0.05 pixels per animation frame and we expect to move 721.0825 pixels in total. After the positioning calculation (which is fine), the expected distance is revised to 785. Note: during the animation, the speed is decremented by 95% on each animation frame so I'm setting the acceleration to 1.05225 (as an arbitary figure).

So if I done things correctly, the speed should be square root of ( ( 2 * 785 * 1.05225 ) + ( 0.05 ^ 2 ) ), which equals 40.65542.

But as you've guessed it, this isn't working and is providing very wonky results? Have I missed something out? Am I using the wrong formula as the speed is not constant (as it is decremented on each animation until the speed reaches 0.05)?

Any help, (of any kind) is gratefully received.

S

Note: I do have a workaround by adjusting the speed using a percentage, e.g. (revised distance / expected distance) * speed that works but isn't pixel perfect. But I'm sure there's a more elegant approach.

hello there. The equations of motion you have used are for frames that have linear acceleration. However when you are deducing the decrement in speed (the effecting acceleration) you calculate the acceleration based on a percentage of the speed of the object. this means the acceleration (total speed decrement) at some point p is going to be smaller than the acceleration at some later point q because the speed at q is lower. try making the acceleration a parameter thatll be an absolute constant i.e. change the speed decrement to a non percentage value like 5 or 10. or you could change ur motion calculation formulae to take into account a non linear acceleration. for example: if you let y be the y cordinate of your object then at some later time t
y = y_0 + vt + (1/2 * a * t^2)
where a == speed decrement * v
or equivalently, the formulae you used in ur program
but now a = speed decrement * v
mind you this may cause some uncertainty because we are using a linear formulae for a nonlinear acceleration

and by that i mean error

Unfortunately I need the animation to feel like a natural action (i.e. fiction stops the object from moving). In addition, the speed may very well differ meaning that a higher speed will take much, much longer to stop with a constant speed as opposed to a decrementing value.

Thanks for your input though, I'll have to see how well the percentage adjustment works in the wild.

However, if there is a true way of calculating with the anticipated speed I would dearly love to hear it :)

after a very large delay, and having fun with my ban... the answer to your question was in my original post. the value a should take (aceleration) isn't simply the decrementing coefficient but the decrementing coefficient times the velocity of the particle at that time.
for the non linear formulae of motion, all i can do is refer you to any classical mechanics or dynamics books. you should find examples answered also in calculus books.

im going to demonstrate with an example:
say you adjust the parameters so that the particle leaves with initial velocity u. you adjust the acceleration coefficient so that at some well defined time interval dt, the velocity is decremented by some coefficient c of its initial value, hence the value of acceleration (change in velocity) is equal to: a=v.c
the velocity of the particle the final point (vfin) then is given by vfin = u + a.dt
here I have missed out an integral sign behind a.dt as I am not sure how to draw one.
in essense then, if you set your program to decrement values from the velocity at some well defined time interval dt, and record the velocity at each point, you then know the acceleration at each point, letting you calculate the final velocity. to find the stopping distance then you take the integral of the vfin function.

## 1. How do you calculate speed?

Speed can be calculated by dividing the distance traveled by the time it took to travel that distance. The formula for calculating speed is speed = distance/time.

## 2. What unit is used to measure speed?

Speed is typically measured in meters per second (m/s) or kilometers per hour (km/h). In some cases, it can also be measured in miles per hour (mph) or feet per second (ft/s).

## 3. What is inertia?

Inertia is the tendency of an object to resist changes in its state of motion. It is a property of matter that describes the resistance of an object to changes in its velocity.

## 4. How do you reverse inertia?

Inertia can be reversed by applying a force in the opposite direction of the object's motion. This force will cause the object to slow down and eventually change its direction of motion.

## 5. Can inertia be negative?

No, inertia cannot be negative. It is a property that describes an object's resistance to changes in motion, but it does not have a negative value. In some cases, inertia can be described as a negative force, but this is a different concept than the property of inertia itself.

• Mechanics
Replies
16
Views
498
• Mechanics
Replies
15
Views
2K
• Mechanics
Replies
11
Views
2K
• Mechanics
Replies
4
Views
1K
• Mechanics
Replies
10
Views
1K
• Mechanics
Replies
2
Views
10K
• Mechanics
Replies
9
Views
1K
• Mechanics
Replies
2
Views
946
• Set Theory, Logic, Probability, Statistics
Replies
10
Views
1K
• Mechanics
Replies
6
Views
1K