forked from RoberAgro/nurbspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_nurbs_surface_merge.py
108 lines (75 loc) · 3.6 KB
/
demo_nurbs_surface_merge.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
""" Example showing how to combine several NURBS surfaces into a single NURBS surface
The NURBS surface must be of the same order to merge them
Merging curves of different degree would require degree elevation (not implemented yet)
"""
# -------------------------------------------------------------------------------------------------------------------- #
# Importing packages
# -------------------------------------------------------------------------------------------------------------------- #
import numpy as np
import nurbspy as nrb
import matplotlib.pyplot as plt
# -------------------------------------------------------------------------------------------------------------------- #
# Create the first NURBS surface
# -------------------------------------------------------------------------------------------------------------------- #
# Define the array of control points
n_dim, n, m = 3, 2, 2
P = np.zeros((n_dim, n, m))
# First row
P[:, 0, 0] = [0.00, 0.00, 0.00]
P[:, 1, 0] = [0.00, 1.00, 0.00]
P[:, 1, 0] = [0.00, 1.00, 0.00]
# Second row
P[:, 0, 1] = [1.00, 0.00, 0.00]
P[:, 1, 1] = [1.00, 1.00, 0.00]
# Create and plot the NURBS surface
nurbsSurface1 = nrb.NurbsSurface(control_points=P)
# -------------------------------------------------------------------------------------------------------------------- #
# Create the second NURBS surface
# -------------------------------------------------------------------------------------------------------------------- #
# Define the array of control points
n_dim, n, m = 3, 2, 2
P = np.zeros((n_dim, n, m))
# First row
P[:, 0, 0] = [0.00, 1.00, 0.00]
P[:, 1, 0] = [0.00, 2.00, 0.00]
# Second row
P[:, 0, 1] = [1.00, 1.00, 0.00]
P[:, 1, 1] = [1.00, 2.00, 0.00]
# Create and plot the NURBS surface
nurbsSurface2 = nrb.NurbsSurface(control_points=P)
# -------------------------------------------------------------------------------------------------------------------- #
# Create the third NURBS surface
# -------------------------------------------------------------------------------------------------------------------- #
# Define the array of control points
n_dim, n, m = 3, 2, 2
P = np.zeros((n_dim, n, m))
# First row
P[:, 0, 0] = [1.00, 0.00, 0.00]
P[:, 1, 0] = [1.00, 1.00, 0.00]
# Second row
P[:, 0, 1] = [2.00, 0.00, 0.00]
P[:, 1, 1] = [2.00, 1.00, 0.00]
# Create and plot the NURBS surface
nurbsSurface3 = nrb.NurbsSurface(control_points=P)
# -------------------------------------------------------------------------------------------------------------------- #
# Merge two NURBS surfaces with a common u-side
# -------------------------------------------------------------------------------------------------------------------- #
# Merge the surfaces
nurbsMerged_u = nurbsSurface1.attach_nurbs_udir(nurbsSurface2)
nurbsMerged_u.P[2, :, :] = 0.5
# Plot the merged surfaces
fig, ax = nurbsSurface1.plot(control_points=True)
nurbsSurface2.plot(fig, ax, control_points=True)
nurbsMerged_u.plot(fig, ax, control_points=True, surface_color='red')
# -------------------------------------------------------------------------------------------------------------------- #
# Merge two NURBS surfaces with a common v-side
# -------------------------------------------------------------------------------------------------------------------- #
# Merge the surfaces
nurbsMerged_v = nurbsSurface1.attach_nurbs_vdir(nurbsSurface3)
nurbsMerged_v.P[2, :, :] = 0.5
# Plot the merged surfaces
fig, ax = nurbsSurface1.plot(control_points=True)
nurbsSurface3.plot(fig, ax, control_points=True)
nurbsMerged_v.plot(fig, ax, control_points=True, surface_color='red')
# Show the figures
plt.show()