[简体中文]
This is a B-spline curve plotting and demonstration program implemented in Python. It utilizes the numpy and matplotlib libraries to provide both static plotting and dynamic, interactive demonstrations.
- Object-Oriented Design: The code is encapsulated in a
BSplineCurveclass, making it clean, understandable, and easy to extend. - Three Types of Node Vectors:
- Uniform B-spline: Nodes are evenly spaced on the parameter axis. The curve generally does not pass through the start and end control points.
- Quasi-uniform B-spline: The first and last nodes have a multiplicity of
k+1, ensuring the curve is "clamped" to the start and end control points. - Piecewise Bézier Curve: By setting specific node multiplicities, the B-spline curve degenerates into a series of connected Bézier curve segments.
- Dual Mode: Static and Interactive:
- Static Plotting: Directly run a script to generate images of the three B-spline curve types.
- Interactive Demonstration: Provides an interactive interface allowing users to modify and observe B-spline curves in real-time by dragging control points and pressing keys.
-
Clone or download this repository.
-
Install the required dependencies. It is recommended to create a
requirements.txtfile with the following content:numpy matplotlib -
Install via pip:
pip install -r requirements.txt
This project includes two usage modes: static plotting (Bsplne.py) and an interactive demonstration (Bsplne_animation.py).
This script is used to generate and display three types of B-spline curves with fixed control points.
Run Directly
python Bsplne.pyAs a Module
You can also import the BSplineCurve class into your own project.
import numpy as np
from Bsplne import BSplineCurve
# Define control points
control_points = np.array(...)
# Create a B-spline curve object
bspline = BSplineCurve(control_points, degree=2)
# Call methods to plot
bspline.draw_uniform_bspline()This script provides a real-time interactive window for exploring how changes to control points and curve types affect the shape of a B-spline curve.
Run the Demo
python Bsplne_animation.pyInteraction Guide
- Drag Control Points: Use the left mouse button to drag the green control points, and the curve will update in real-time.
- Switch Curve Types: With the window active, press the number keys
1,2, or3to switch.1: Uniform B-spline2: Quasi-uniform B-spline (Default)3: Piecewise Bézier (Only available ifn % k == 0)
A B-spline curve is defined by its control points
The basis functions
By convention, 0/0 = 0.
- Parameter Requirement: The number of control points (
n+1) must be greater than or equal to the degree of the B-spline (k), i.e.,n >= k. - Piecewise Bézier Condition: To generate a piecewise Bézier curve, the number of control points minus one (
n) must be an integer multiple of the degree (k), i.e.,n % k == 0, andk >= 1. - Performance: For high-degree B-splines (e.g.,
k > 5), the computational complexity increases due to deeper recursion, which may affect performance.
This project is licensed under the MIT License.
