From f43f909bf20dafb2c10520815282046cffe495f2 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Sat, 22 Aug 2020 16:02:17 +0200 Subject: Refactoring, Bezier Refactored module layout. Added missing dependencies to setup. Added time scaling to curves. --- AutopyExtended/Curve/test.py | 55 -------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 AutopyExtended/Curve/test.py (limited to 'AutopyExtended/Curve/test.py') diff --git a/AutopyExtended/Curve/test.py b/AutopyExtended/Curve/test.py deleted file mode 100644 index ab9ee6c..0000000 --- a/AutopyExtended/Curve/test.py +++ /dev/null @@ -1,55 +0,0 @@ -import numpy as np -from scipy.special import comb - -def bernstein_poly(i, n, t): - """ - The Bernstein polynomial of n, i as a function of t - """ - - return comb(n, i) * ( t**(n-i) ) * (1 - t)**i - - - -def bezier_curve(points, nTimes=1000): - """ - Given a set of control points, return the - bezier curve defined by the control points. - points should be a list of lists, or list of tuples - such as [ [1,1], - [2,3], - [4,5], ..[Xn, Yn] ] - nTimes is the number of time steps, defaults to 1000 - See http://processingjs.nihongoresources.com/bezierinfo/ - """ - - nPoints = len(points) - xPoints = np.array([p[0] for p in points]) - yPoints = np.array([p[1] for p in points]) - - t = np.linspace(0.0, 1.0, nTimes) - - polynomial_array = np.array([ bernstein_poly(i, nPoints-1, t) for i in range(0, nPoints) ]) - - xvals = np.dot(xPoints, polynomial_array) - yvals = np.dot(yPoints, polynomial_array) - - return xvals, yvals - - - -if __name__ == "__main__": - from matplotlib import pyplot as plt - - nPoints = 4 - points = np.random.rand(nPoints,2)*200 - xpoints = [p[0] for p in points] - ypoints = [p[1] for p in points] - - xvals, yvals = bezier_curve(points, nTimes=1000) - plt.plot(xvals, yvals) - plt.plot(xpoints, ypoints, "ro") - for nr in range(len(points)): - plt.text(points[nr][0], points[nr][1], nr) - - - plt.show() -- cgit v1.2.1