I need to calculate the position of a view as it travels from point A to point B. There will be an input value that will change linearly, and based on that input value I need to calculate the position of my view. By the end both the input value and my view will have moved exactly the same amount. The view only moves along one axis.
The tricky part is I want to ease the animation in and out, so at the begin and end of the movement it's moving slower than the input value, and during the middle it will need to move faster than it, in order to makeup the lost travel distance from the slow start and end.
So basically the formula I'm trying to write will have a velocity curve that looks something like this.
So my signature looks something like this:
func smoothedPosition(position: CGFloat, minPosition: CGFloat, maxPosition: CGFloat) -> CGFloat {
And the results need to even out over time so it should be something like
where smoothedPosition(position: 100, minPosition: 100, maxPosition: 200) expect 100
where smoothedPosition(position: 101, minPosition: 100, maxPosition: 200)) expect something between 100 and 101
where smoothedPosition(position: 150, minPosition: 100, maxPosition: 200)) expect 150
where smoothedPosition(position: 199, minPosition: 100, maxPosition: 200)) expect something between 199 and 200
where smoothedPosition(position: 200, minPosition: 100, maxPosition: 200)) expect 200
I'm sure there's some sort of equation to do exactly this, but maths was never my strong point. Can somebody point me in the right direction.