Example #1
0
# Define the order of the basis polynomials
# Linear (p = 1), Quadratic (p = 2), Cubic (p = 3), etc.
# Set p = n (number of control points minus one) to obtain a Bezier
p = 3
q = 3

# Define the knot vectors (clamped spline)
# p+1 zeros, n-p equispaced points between 0 and 1, and p+1 ones.  In total r+1 points where r=n+p+1
# q+1 zeros, m-p equispaced points between 0 and 1, and q+1 ones. In total s+1 points where s=m+q+1
U = np.concatenate((np.zeros(p), np.linspace(0, 1, n - p + 2), np.ones(p)))
V = np.concatenate((np.zeros(q), np.linspace(0, 1, m - q + 2), np.ones(q)))

# Create and plot the NURBS surface
nurbsSurface = nrb.NurbsSurface(control_points=P,
                                weights=W,
                                u_degree=p,
                                v_degree=q,
                                u_knots=U,
                                v_knots=V)
nurbsSurface.plot(surface=True, control_points=True)
S_func = nurbsSurface.get_value

# -------------------------------------------------------------------------------------------------------------------- #
# Check the analytic derivatives against a finite difference aproximation
# -------------------------------------------------------------------------------------------------------------------- #
# Define a (u,v) parametrization suitable for finite differences. 1D arrays of (u,v) query points
h = 1e-4
hh = h + h**2
Nu, Nv = 50, 50
u = np.linspace(0.00 + h, 1.00 - h, Nu)
v = np.linspace(0.00 + h, 1.00 - h, Nv)
[u, v] = np.meshgrid(u, v, indexing='xy')
Example #2
0
# Third row
P[:, 0, 2] = [0.00, 3.00, 2.00]
P[:, 1, 2] = [1.00, 2.00, 2.00]
P[:, 2, 2] = [2.00, 1.50, 2.00]
P[:, 3, 2] = [3.00, 2.00, 2.00]
P[:, 4, 2] = [4.00, 3.00, 2.00]

# Fourth row
P[:, 0, 3] = [0.50, 3.00, 3.00]
P[:, 1, 3] = [1.00, 2.50, 3.00]
P[:, 2, 3] = [2.00, 2.00, 3.00]
P[:, 3, 3] = [3.00, 2.50, 3.00]
P[:, 4, 3] = [3.50, 3.00, 3.00]

# Create and the NURBS surface
nurbsSurface = nrb.NurbsSurface(control_points=P)

# Define point to be projected
P0 = np.asarray([0.50, 0.50, 0.50]).reshape((3,1))

# Compute projected time
u0, v0 = nurbsSurface.project_point_to_surface(P0)
S0 = nurbsSurface.get_value(u0, v0)

# Plot the NURBS surface and the projected point
fig, ax = nurbsSurface.plot()
Px, Py, Pz = P0.flatten()
Sx, Sy, Sz = S0.flatten()
ax.plot([Px, Sx], [Py, Sy], [Pz, Sz], color='black', linestyle='--', marker='o', markeredgecolor='r', markerfacecolor='w')
plt.show()
Example #3
0
P[:, 1, 1] = [1.00, 2.00, 1.00]
P[:, 2, 1] = [2.00, 1.50, 1.00]
P[:, 3, 1] = [3.00, 2.00, 1.00]
P[:, 4, 1] = [4.00, 3.00, 1.00]

# Third row
P[:, 0, 2] = [0.00, 3.00, 2.00]
P[:, 1, 2] = [1.00, 2.00, 2.00]
P[:, 2, 2] = [2.00, 1.50, 2.00]
P[:, 3, 2] = [3.00, 2.00, 2.00]
P[:, 4, 2] = [4.00, 3.00, 2.00]

# Fourth row
P[:, 0, 3] = [0.50, 3.00, 3.00]
P[:, 1, 3] = [1.00, 2.50, 3.00]
P[:, 2, 3] = [2.00, 2.00, 3.00]
P[:, 3, 3] = [3.00, 2.50, 3.00]
P[:, 4, 3] = [3.50, 3.00, 3.00]

# Define the array of control point weights
W = np.zeros((n, m))
W[:, 0] = np.asarray([1, 1, 5, 1, 1])
W[:, 1] = np.asarray([1, 1, 5, 1, 1])
W[:, 2] = np.asarray([1, 1, 5, 1, 1])
W[:, 3] = np.asarray([1, 1, 0.5, 1, 1])

# Create and plot the Bezier surface
bezierSurface = nrb.NurbsSurface(control_points=P, weights=W)
bezierSurface.plot(control_points=True)
plt.show()
Example #4
0
m = np.shape(P)[2] - 1

# Define the order of the basis polynomials
# Linear (p = 1), Quadratic (p = 2), Cubic (p = 3), etc.
# Set p = n (number of control points minus one) to obtain a Bezier
p = 3
q = 3

# Define the knot vectors (clamped spline)
# p+1 zeros, n-p equispaced points between 0 and 1, and p+1 ones.  In total r+1 points where r=n+p+1
# q+1 zeros, m-p equispaced points between 0 and 1, and q+1 ones. In total s+1 points where s=m+q+1
U = np.concatenate((np.zeros(p), np.linspace(0, 1, n - p + 2), np.ones(p)))
V = np.concatenate((np.zeros(q), np.linspace(0, 1, m - q + 2), np.ones(q)))

# Create and plot the B-Spline surface
bsplineSurface = nrb.NurbsSurface(control_points=P, u_degree=p, v_degree=q, u_knots=U, v_knots=V)
fig, ax = bsplineSurface.plot(surface=False, control_points=False)

# Plot the blade surface using a colormap based on curvature
bsplineSurface.plot_surface(fig, ax, color='mean_curvature', colorbar=True)

# Plot the vectors normal to the surface
bsplineSurface.plot_normals(fig, ax, scale=0.30)

# Plot isoparametric curves
bsplineSurface.plot_isocurve_u(fig, ax, np.linspace(0, 1, 5))
bsplineSurface.plot_isocurve_v(fig, ax, np.linspace(0, 1, 5))

# Show the figure
plt.show()
Example #5
0
# 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]