forked from RoberAgro/nurbspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_nurbs_surface_coons.py
72 lines (52 loc) · 2.5 KB
/
demo_nurbs_surface_coons.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
""" Example showing how to create a Coons NURBS surface """
# -------------------------------------------------------------------------------------------------------------------- #
# Importing packages
# -------------------------------------------------------------------------------------------------------------------- #
import numpy as np
import nurbspy as nrb
import matplotlib.pyplot as plt
# -------------------------------------------------------------------------------------------------------------------- #
# Coons surface example
# -------------------------------------------------------------------------------------------------------------------- #
# Define the south boundary (rational Bézier curve)
P = np.zeros((3, 4))
P[:, 0] = [0.00, 0.00, 0.00]
P[:, 1] = [0.33, 0.00, -0.40]
P[:, 2] = [0.66, 0.10, 0.60]
P[:, 3] = [1.00, 0.20, 0.40]
W = np.asarray([1, 2, 2, 1])
nurbsCurve_south = nrb.NurbsCurve(control_points=P, weights=W)
# Define the north boundary (rational Bézier curve)
P = np.zeros((3, 4))
P[:, 0] = [0.05, 1.00, 0.00]
P[:, 1] = [0.33, 1.15, 0.40]
P[:, 2] = [0.66, 1.15, 0.00]
P[:, 3] = [1.05, 1.25, 0.40]
W = np.asarray([1, 2, 2, 1])
nurbsCurve_north = nrb.NurbsCurve(control_points=P, weights=W)
# Define the west boundary (rational Bézier curve)
P = np.zeros((3, 3))
P[:, 0] = nurbsCurve_south.P[:, 0]
P[:, 1] = [-0.20, 0.50, -0.40]
P[:, 2] = nurbsCurve_north.P[:, 0]
W = np.asarray([nurbsCurve_south.W[0], 1, nurbsCurve_north.W[0]])
nurbsCurve_west = nrb.NurbsCurve(control_points=P, weights=W)
# Define the east boundary (rational Bézier curve)
P = np.zeros((3, 3))
P[:, 0] = nurbsCurve_south.P[:, -1]
P[:, 1] = [1.15, 0.50, 0.30]
P[:, 2] = nurbsCurve_north.P[:, -1]
W = np.asarray([nurbsCurve_south.W[-1], 1, nurbsCurve_north.W[-1]])
nurbsCurve_east = nrb.NurbsCurve(control_points=P, weights=W)
# Create and plot the Coons NURBS surface
coonsNurbsSurface = nrb.NurbsSurfaceCoons(nurbsCurve_south, nurbsCurve_north, nurbsCurve_west, nurbsCurve_east).NurbsSurface
fig, ax = coonsNurbsSurface.plot(surface=True, surface_color='blue', control_points=False)
# Plot isoparametric curves
coonsNurbsSurface.plot_isocurve_u(fig, ax, np.linspace(0, 1, 5))
coonsNurbsSurface.plot_isocurve_v(fig, ax, np.linspace(0, 1, 5))
# Plot the boundary NURBS curves
nurbsCurve_south.plot_curve(fig, ax, color='b', linewidth=2.5)
nurbsCurve_north.plot_curve(fig, ax, color='b', linewidth=2.5)
nurbsCurve_west.plot_curve(fig, ax, color='b', linewidth=2.5)
nurbsCurve_east.plot_curve(fig, ax, color='b', linewidth=2.5)
plt.show()