Question: I need help in a Math logic issue.
Let say I have an object that can be manipulate (move) by user.
After the user moved the object I would like the object to continue moving and decelerate to a stop.

Example, when a user move an object from point A to B with a total distance of 100pixel in X axis, after user release a finger, I want to let the object continue moving and decelerate to a stop from point B to point C.

So how can I calculate the new distance of point C if I set the time for it to decelerate and stop in 2sec?

Thank you!

Answer: 
d = ½at² + vit + d0

d0 is the point at which the user "let go". Calculate vi from the motion before letting go. Set a to something negative; you'll have to fiddle with this to get it to feel right. Increment t from 0 through 2. d is where the object will end up. Remember that a and vi are **vectors** pointing in opposite directions, and that d0 and d are **points**.
If all you want is the *distance* from **B** to **C**, that's easy. If the object went a distance N pixels (say 100) from **A** to **B** in k seconds, then the distance from **B** to **C** will be N/k.

If you want the *location* of **C**, so that A, B and C are integers on the x-axis, C = B+(B-A)/k.

If you want to *animate* the motion, so that you can update the position x at every time step dt (say 0.1 seconds), then start (at **B**) with v=N/k, and at each step,

```
x += v * dt
v -= N * dt/(2 * k)

```

(Be sure to use floats, not integers, or the round-off error will ruin the effect.)