From 347ad577e0344ccf93345377f9b1f5d79227bfbd Mon Sep 17 00:00:00 2001 From: Amritpal Singh <124516230+amritpalsingh52@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:35:04 +0530 Subject: [PATCH] added a program solution that show BSpline curve B-splines are a generalization of Bezier curves and offer more control points, allowing for smoother and more complex curves. They are commonly used in computer-aided design (CAD) and computer graphics if ypou find my solution valid then please merge it and label it as hacktoberfest --- graphics/Bspline_curve.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 graphics/Bspline_curve.py diff --git a/graphics/Bspline_curve.py b/graphics/Bspline_curve.py new file mode 100644 index 000000000000..f8b46c662d56 --- /dev/null +++ b/graphics/Bspline_curve.py @@ -0,0 +1,25 @@ +import numpy as np +import matplotlib.pyplot as plt +from scipy.interpolate import BSpline + +# Define control points (x, y) +control_points = np.array([[1, 2], [2, 3], [3, 5], [4, 4], [5, 2]]) + +# Create B-spline object with degree=3 (cubic B-spline) +degree = 3 +t = range(len(control_points) + degree + 1) +spl = BSpline(t, control_points, degree) + +# Evaluate the B-spline curve +num_points = 1000 +curve_points = np.array([spl(i) for i in np.linspace(0, len(control_points) - degree, num_points)]) + +# Plot control points and B-spline curve +plt.plot(control_points[:, 0], control_points[:, 1], 'ro-', label='Control Points') +plt.plot(curve_points[:, 0], curve_points[:, 1], 'b-', label='B-spline Curve') +plt.xlabel('X') +plt.ylabel('Y') +plt.legend() +plt.title('B-spline Curve') +plt.grid(True) +plt.show()