def drawSpline(self, xCursor, yCursor): # Track cursor location self.drawCursor(xCursor, yCursor) # Check if number of points is sufficient if len(self.interpolationPoints[0]) + len(xCursor) < self.p + 1: return # Get spline controlPoints, knotVector = pysplinekernel.interpolateWithBSplineCurve( [ self.interpolationPoints[0] + xCursor, self.interpolationPoints[1] + yCursor ], self.p) # Get parameters (10 per segments) t = np.linspace(0.0, 1.0, (len(self.interpolationPoints[0]) - 1) * 10) # Remove previous spline and draw new one xc, yc = pysplinekernel.evaluate2DCurve(t, controlPoints[0], controlPoints[1], knotVector) self.spline.remove() self.spline, = self.ax.plot(xc, yc, 'b') # Draw control polygon self.drawControlPolygon(controlPoints) #Update figure self.fig.canvas.draw()
import numpy import matplotlib.pyplot as plt # ----------------------------------------------------- n = 101 U1 = [0.0, 0.0, 0.25, 0.5, 0.75, 1.0, 1.0] U2 = [0.0, 0.0, 0.0, 0.33, 0.66, 1.0, 1.0, 1.0] U3 = [0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0] U4 = [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0] t = numpy.linspace(0.0, 1.0, n) P = [[1.5, 2.0, 2.5, 1.0, 1.0], [1.0, 0.5, 2.0, 2.5, 0.5]] xc1, yc1 = evaluate2DCurve(t, P[0], P[1], U1) xc2, yc2 = evaluate2DCurve(t, P[0], P[1], U2) xc3, yc3 = evaluate2DCurve(t, P[0], P[1], U3) xc4, yc4 = evaluate2DCurve(t, P[0], P[1], U4) plt.plot(xc1, yc1, label='p = 1') plt.plot(xc2, yc2, label='p = 2') plt.plot(xc3, yc3, label='p = 3') plt.plot(xc4, yc4, label='p = 4') plt.plot(P[0], P[1], 'rx') plt.legend() plt.show()
import pysplinekernel import numpy import matplotlib.pyplot as plt n = 101 U1 = [0.0, 0.0, 0.25, 0.5, 0.75, 1.0, 1.0] U2 = [0.0, 0.0, 0.0, 0.33, 0.66, 1.0, 1.0, 1.0] U3 = [0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0] U4 = [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0] t = numpy.linspace(0.0, 1.0, n) P = [[1.5, 2.0, 2.5, 1.0, 1.0], [1.0, 0.5, 2.0, 2.5, 0.5]] xc1, yc1 = pysplinekernel.evaluate2DCurve(t, P[0], P[1], U1) xc2, yc2 = pysplinekernel.evaluate2DCurve(t, P[0], P[1], U2) xc3, yc3 = pysplinekernel.evaluate2DCurve(t, P[0], P[1], U3) xc4, yc4 = pysplinekernel.evaluate2DCurve(t, P[0], P[1], U4) plt.plot(xc1, yc1, label='p = 1') plt.plot(xc2, yc2, label='p = 2') plt.plot(xc3, yc3, label='p = 3') plt.plot(xc4, yc4, label='p = 4') plt.plot(P[0], P[1], 'rx') plt.legend() plt.show()
# --- Python imports --- import numpy as np import matplotlib.pyplot as plt # --- Splinekernel imports --- from pysplinekernel import interpolateWithBSplineCurve, evaluate2DCurve # ----------------------------------------------------- interpolationPoints = [[0.0, 3.0, -1.0, -4.0, -4.0, -3.0], [0.0, 4.0, 4.0, 0.0, -3.0, -3.0]] polynomialDegree = 3 controlPoints, knotVector = interpolateWithBSplineCurve( interpolationPoints, polynomialDegree) t = np.linspace(0.0, 1.0, 100) xc, yc = evaluate2DCurve(t, controlPoints[0], controlPoints[1], knotVector) plt.plot(controlPoints[0], controlPoints[1], 'r-x') plt.plot(xc, yc, 'b') plt.plot(interpolationPoints[0], interpolationPoints[1], 'o') plt.show()
import pysplinekernel import numpy import matplotlib.pyplot as plt interpolationPoints = [[0.0, 3.0, -1.0, -4.0, -4.0, -3.0], [0.0, 4.0, 4.0, 0.0, -3.0, -3.0]] polynomialDegree = 3 controlPoints, knotVector = pysplinekernel.interpolateWithBSplineCurve( interpolationPoints, polynomialDegree) t = numpy.linspace(0.0, 1.0, 100) xc, yc = pysplinekernel.evaluate2DCurve(t, controlPoints[0], controlPoints[1], knotVector) plt.plot(controlPoints[0], controlPoints[1], 'r-x') plt.plot(xc, yc, 'b') plt.plot(interpolationPoints[0], interpolationPoints[1], 'o') plt.show()