Skip to content

added a program solution that show BSpline curve #9615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions graphics/Bspline_curve.py
Original file line number Diff line number Diff line change
@@ -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()