-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNURBSBasis.py
51 lines (37 loc) · 1.44 KB
/
NURBSBasis.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
47
48
49
50
51
import numpy as np
import matplotlib.pyplot as plt
import math
from BSplineBasis import CoxDeBoorRecursion
from KnotVectors import OpenUniformKnotVector
def NurbsBasis(i, order, Knots, t, Weights, countPoints):
top = Weights[i] * CoxDeBoorRecursion(i, order, Knots, t)
bottom = 0.
for j in range(countPoints):
bottom += Weights[j] * CoxDeBoorRecursion(j, order, Knots, t)
return top / bottom
def NurbsBasisGraph(Knots, order, i, T, Weights, countPoints):
values = []
for t in T:
values.append(NurbsBasis(i, order, Knots, t, Weights, countPoints))
return np.asarray(values)
if __name__ == "__main__":
countPoints = 5
order = 3
Knots = OpenUniformKnotVector(order, countPoints, True)
WeightsA = np.asarray([1, 1, 0, 1, 1])
WeightsB = np.asarray([1, 1, 0.25, 1, 1])
WeightsC = np.asarray([1, 1, 1, 1, 1])
WeightsD = np.asarray([1, 1, 5, 1, 1])
T = np.arange(0., 1., 0.01)
for i in range(countPoints):
plt.plot(T, NurbsBasisGraph(Knots, order, i, T, WeightsA, countPoints))
plt.show()
for i in range(countPoints):
plt.plot(T, NurbsBasisGraph(Knots, order, i, T, WeightsB, countPoints))
plt.show()
for i in range(countPoints):
plt.plot(T, NurbsBasisGraph(Knots, order, i, T, WeightsC, countPoints))
plt.show()
for i in range(countPoints):
plt.plot(T, NurbsBasisGraph(Knots, order, i, T, WeightsD, countPoints))
plt.show()