def __init__(self, parent=None): super(Window, self).__init__(parent) # Create a NURBS surface instance self.surf = ns.Surface() # Set up the NURBS surface self.surf.read_ctrlpts("data.txt") self.surf.degree_u = 3 self.surf.degree_v = 3 self.surf.knotvector_u = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] self.surf.knotvector_v = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] # Calculate surface points self.surf.evaluate_rational() self.coeff = 10 # A figure instance to plot on self.figure = plot.figure(figsize=(10.67, 8), dpi=96) # This is the Canvas Widget that displays the `figure` # it takes the `figure` instance as a parameter to __init__ self.canvas = FigureCanvas(self.figure) # This is the Navigation widget # it takes the Canvas widget and a parent self.toolbar = NavigationToolbar(self.canvas, self) # Just some slider connected to `plot` method self.slider = QSlider(Qt.Horizontal) self.slider.setMinimum(1) self.slider.setMaximum(36) self.slider.setValue(10) self.slider.valueChanged.connect(self.plot) self.label = QLabel("Quality of drawing slider (left is best right is worst)") self.label.setAlignment(Qt.AlignCenter) # Set the layout layout = QVBoxLayout() layout.addWidget(self.toolbar) layout.addWidget(self.canvas) layout.addWidget(self.label) layout.addWidget(self.slider) self.setLayout(layout)
# -*- coding: utf-8 -*- """ Examples for the NURBS-Python Package Released under MIT License Developed by Onur Rauf Bingol (c) 2016-2017 """ from nurbs import Surface as ns from nurbs import utilities as utils from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Create a NURBS surface instance surf = ns.Surface() # Set up the NURBS surface surf.read_ctrlpts("data\CP_Surface2.txt") surf.degree_u = 3 surf.degree_v = 3 surf.knotvector_u = utils.knotvector_autogen(surf.degree_u, 6) surf.knotvector_v = utils.knotvector_autogen(surf.degree_v, 6) # Evaluate surface surf.evaluate_rational() # Calculate 1st order surface derivative at the given u and v u = 0.2 v = 0.9 surftan = surf.tangent(u, v) print("* Surface point at u = %.2f and v = %.2f is (%.2f, %.2f, %.2f)" % (u, v, surftan[0][0], surftan[0][1], surftan[0][2]))
Up.calculate_basis_functions() Np = Up.get_basis_functions() # Knot vector and basis functions for V direction Uq = Knot.Knot(dimension, degree_q, num_points_v) Uq.create_knot_vector() # Display and get knot vector V print('Knot vector V:') knot_vector_q = Uq.get_knot_vector(True) Uq.calculate_spans() spans_q = Uq.get_spans() Uq.calculate_basis_functions() Nq = Uq.get_basis_functions() # Surface point operations S = Surface.Surface(degree_p, degree_q, Pv, Np, Nq, spans_p, spans_q) S.calculate() S_points = S.get_result() S.write() # Get surface points x_coords = [] y_coords = [] z_coords = [] for s in S_points: x_coords.append(s['x']) y_coords.append(s['y']) z_coords.append(s['z']) # # Knot insertion