AnticipateOvershootInterpolator

AnticipateOvershootInterpolator的源码如下:

package android.view.animation;

public class AnticipateOvershootInterpolator extends BaseInterpolator {
    private final float mTension;

    public AnticipateOvershootInterpolator() {
        mTension = 2.0f * 1.5f;
    }

    public AnticipateOvershootInterpolator(float tension) {
        mTension = tension * 1.5f;
    }

    public AnticipateOvershootInterpolator(float tension, float extraTension) {
        mTension = tension * extraTension;
    }

    private static float a(float t, float s) {
        return t * t * ((s + 1) * t - s);
    }

    private static float o(float t, float s) {
        return t * t * ((s + 1) * t + s);
    }

    public float getInterpolation(float t) {
        if (t < 0.5f) {
            return 0.5f * a(t * 2.0f, mTension);
        } else {
            return 0.5f * (o(t * 2.0f - 2.0f, mTension) + 2.0f);
        }
    }
}

float getInterpolation(float input)的实现,可以知道,这个是分段函数。

Matlab中创建一个a.m文件,编写一个函数,实现如下:

function [ y ] = a(x , s)
    y = x .* x .* ((s + 1) .* x - s);
end

Matlab中创建一个o.m文件,编写一个函数,实现如下:

function [ y ] = o(x , s)
    y = x .* x .* ((s + 1) .* x + s);
end

Matlab中创建一个anticipateOvershootInterpolator1.m文件,编写一个函数,实现如下:

function [ y ] = anticipateOvershootInterpolator1( x, tension )
    y = 0.5 .* a(x .* 2.0, tension);
end

Matlab中创建一个anticipateOvershootInterpolator2.m文件,编写一个函数,实现如下:

function [ y ] = anticipateOvershootInterpolator2( x, tension )
    y = 0.5 .* (o(x .* 2.0 - 2.0, tension) + 2.0);
end

Matlab的命令窗口中输入如下命令:

tension=3.0;
x1=linspace(0,0.5,50);
x2=linspace(0.5,1,50);
y1 = anticipateOvershootInterpolator1(x1,3.0);
y2 = anticipateOvershootInterpolator2(x2,3.0);
plot(x1,y1);
hold on;
plot(x2,y2);
title('AnticipateOvershootInterpolator');
grid on

得到下面的曲线图: