#! usr/bin/python
# -*-coding:utf-8 -*

import matplotlib.pyplot as plt

from scipy import interpolate

modele = [
        [0,     2.25/2],
        [0.75,  2.828/2],
        [2.25,  3.906/2],
        [3+3/8, 4.51/2],
        [4.5,   4.766/2],
        [5+7/8, 4.563/2],
        [7.25,  3.703/2],
        [8+5/8, 2.472/2],
        [9+3/8, 1.965/2],
        [10,    1.797/2],
        [10+7/8,1.87/2],
        [11.75, 2.094/2],
        [12+5/8,2.406/2],
        [13.5,  2.547/2],
        [15,    0]]

X = [P[0] for P in modele]
Y = [P[1] for P in modele]

def interpolation(x):
    r = float(0)
    n = len(X)
    for i in range(n):
        p = Y[i]
        for j in range(n):
            if j != i:
                p *= (x - X[j]) / (X[i] - X[j])
        r += p
    return r


f = interpolate.interp1d(X,Y, fill_value="extrapolate", kind="cubic")

plt.plot(X,Y,'r')

N = 100

X2 = [ k*15 / N for k in range(N+1) ]
Y2 = [ interpolation(x) for x in X2 ]
plt.plot(X2,Y2,'b')

Y3 = [ f(x) for x in X2 ]
plt.plot(X2,Y3,'g')

plt.axis([0,15,0,3])
plt.show()

s = ""
n = len(X2) 
for i in range(1,len(X2)-1):
    s += "[" + str(10*X2[n-1-i]) + "," + str(round(10*Y3[n-1-i] - 2, 2)) + "], \n"
for i in range(len(X2)):
    s += "[" + str(10*X2[i]) + "," + str(round(10*Y3[i], 2)) + "], \n"
print(s)
    

