-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbezier.py
46 lines (36 loc) · 947 Bytes
/
bezier.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
34
35
36
37
38
39
40
41
42
43
44
45
46
import math
import matplotlib.pyplot as plt
u = 0.001
def binomial(i, n):
return math.factorial(n) / float(
math.factorial(i) * math.factorial(n - i))
def bezier(px , py , u , x , y):
n = len(px)
for i in range(n):
bio = binomial(i , n - 1)
t = 0
while t < 1:
resX = math.pow(t , i) * math.pow( (1 - t) , n - i - 1) * px[i]
resY = math.pow(t , i) * math.pow( (1 - t) , n - i - 1) * py[i]
x.append(bio * resX)
y.append(bio * resY)
t = t + u
for i in range(n - 1):
for j in range(1000):
x[j] = x[j] + x[(1000*(i+1)) + j]
y[j] = y[j] + y[(1000*(i+1)) + j]
def main():
x = []
y = []
n = int(input("How many point do you want?"))
px , py = [] , []
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 : ")))
bezier(px , py , u , x , y)
x = x[:1000]
y = y[:1000]
plt.plot(x , y)
plt.show()
if __name__ == '__main__':
main()