-
Notifications
You must be signed in to change notification settings - Fork 0
/
hermite.py
34 lines (27 loc) · 1.07 KB
/
hermite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import math
import matplotlib.pyplot as plt
x = []
y = []
u = 0.001
def hermite(px , py , qx , qy , prx , pry , qrx , qry , u):
tt = u
while(tt < 1):
resx = (1-3*math.pow(tt,2)+2*math.pow(tt,3))*px+(3*math.pow(tt,2)-2*math.pow(tt,3))*qx+(tt-2*math.pow(tt,2)+math.pow(tt,3))*prx+(-math.pow(tt,2)+math.pow(tt,3))*qrx;
resy = (1-3*math.pow(tt,2)+2*math.pow(tt,3))*py+(3*math.pow(tt,2)-2*math.pow(tt,3))*qy+(tt-2*math.pow(tt,2)+math.pow(tt,3))*pry+(-math.pow(tt,2)+math.pow(tt,3))*qry;
x.append(resx)
y.append(resy)
tt = tt+u
def main():
n = int(input("How many point do you want?"))
px , py , qx , qy , prx , pry , qrx , qry = [] , [] , [] , [] , [] , [] , [] , []
for i in range(n):
px.append(int(input(str(i + 1) +"th point x : ")))
py.append(int(input(str(i + 1) +"th point y : ")))
prx.append(int(input(str(i + 1) +"th point rx : ")))
pry.append(int(input(str(i + 1) +"th point ry : ")))
if(i > 0):
hermite(px[i - 1] , py[i - 1] , px[i] , py[i] , prx[i - 1] , pry[i - 1] , prx[i] , pry[i] , u)
plt.plot(x , y)
plt.show()
if __name__ == '__main__':
main()