Skip to content

Instantly share code, notes, and snippets.

@ixxra
Created October 14, 2013 15:18
Show Gist options
  • Select an option

  • Save ixxra/6977300 to your computer and use it in GitHub Desktop.

Select an option

Save ixxra/6977300 to your computer and use it in GitHub Desktop.
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
import pylab
import scipy.interpolate
#Lo siguiente es para separar la lista de puntos en los de coordenadas x y los de coordenadas y
'''
A=[[950,1090],[850,1290],[810,1450], [758,1705], [320, 2340] , [860, 1950] , [750,2875] , [1090,2090] , [1148,3020] , [1360, 2110] , [1650,2805] , [1580,1910] , [1700,1710] , [2040,2050] , [2000,1790] , [1840,1510] , [1740,1350] , [1610,1150]]
X=[]
Y=[]
t=len(A)
for i in range(len(A)):
a=A[i]
m=a[0]
n=a[1]
X=X+[m]
Y=Y+[n]
print X
print Y
'''
X=[950, 850, 810, 758, 320, 860, 750, 1090, 1148, 1360, 1650, 1580, 1700, 2040, 2000, 1840, 1740]
Y=[1090, 1290, 1450, 1705, 2340, 1950, 2875, 2090, 3020, 2110, 2805, 1910, 1710, 2050, 1790, 1510, 1350]
NX=[]
NY=[]
T = np.linspace(0, 1, len(X))
tt = []
xx = []
yy = []
p = []
for i in range(1,len(T) - 2,2):
T0=T[i]
T1=T[i+1]
T2=T[i+2]
X0=X[i]
X1=X[i+1]
X2=X[i+2]
Y0=Y[i]
Y1=Y[i+1]
Y2=Y[i+2]
C1=X[i]
C2=float(X[i+1]-C1)/(T1-T0)
C3=float(X[i+2]-C1-C2*(T2-T0))/((T2-T0)*(T2-T1))
D1=Y[i]
D2=float(Y[i+1]-D1)/(T1-T0)
D3=float(Y[i+2]-D1-D2*(T2-T0))/((T2-T0)*(T2-T1))
#f es la funcion cuadratica que pasa por los tres puntos y dados los 3 valores de x a usar
f= lambda t: C1+C2*(t-T0)+C3*(t-T0)*(t-T1)
g = lambda t: D1 + D2*(t - T0) + D3*(t - T0)*(t - T1)
#XMAX=max(X0,X1,X2)
#XMIN=min(X0,X1,X2)
#x=np.arange(XMIN,XMAX)
#print x
#y=[f(t) for t in x]
#print y
t = np.linspace(T0, T2, 10)
z = map(f, t)
w = map(g, t)
tt += t.tolist()
xx += z
yy += w
'''
for m in range(len(x)):
NX=[x[m]]+NX
NY=[y[m]]+NY
#print NX
#print NY
'''
plt.plot(xx, yy,'-')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment