import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

ax = plt.figure().add_subplot(projection='3d')

R = 0.2
pi = np.pi
x1 = np.arange(0,1,0.01)
x2 = np.arange(-0.5,0.5,0.02)
X1, X2 = np.meshgrid( x1, x2 )
# print(X2)

# definition du cylindre
v1_cyl = R*np.outer( np.cos(2*pi*X1), np.ones(np.size(X2)) )
v2_cyl = R*np.outer( np.sin(2*pi*X1), np.ones(np.size(X2)) )
v3_cyl =   np.outer( np.ones(np.size(X1)), X2 )

N = 6
r = 0.1 #taille des corrugations

def G1(t):
    return -r*np.sin(4*pi*t)
def G2(t):
    return 2*r*np.sin(2*pi*t)

NX = N*X1 - np.floor( N*X1 )
# definition de G1*t1 
t1_1 = np.outer( - np.sin(2*pi*X1)*G1(NX), np.ones(np.size(X2))  )
t1_2 = np.outer(   np.cos(2*pi*X1)*G1(NX), np.ones(np.size(X2))  )
t1_3 = np.outer(    0*G1(NX),              np.zeros(np.size(X2)) )
# definition de G2*n 
n_1 = np.outer(   np.cos(2*pi*X1)*G2(NX), np.ones(np.size(X2))  )
n_2 = np.outer(   np.sin(2*pi*X1)*G2(NX), np.ones(np.size(X2))  )
n_3 = np.outer(   0*G2(NX),               np.zeros(np.size(X2)) )

surf = ax.plot_surface(v1_cyl +(1/N)*(t1_1+n_1),
                       v2_cyl +(1/N)*(t1_2+n_2),
                       v3_cyl +(1/N)*(t1_3+n_3),
                cmap=cm.coolwarm, linewidth=0, antialiased=False)

#surf_cyl = ax.plot_wireframe( v1_cyl, v2_cyl, v3_cyl )
plt.show()



