A comprehensive visualization tool for understanding and interacting with Bezier curves. This tool allows users to draw curves, visualize Bernstein polynomials, and understand the mathematical concepts behind Bezier curves through interactive visualizations.
Thank you to the following resources for providing valuable information for this project: https://en.wikipedia.org/wiki/B%C3%A9zier_curve
Parts adapted and ported from Sage to Python from https://commons.wikimedia.org/wiki/File:Bernstein_poly_4.svg
To https://github.com/jegork/dysgraphia/blob/7edffa08a5c08571aeb080a625792797981d0607/bezier.py for the Bezier curve fitting algorithm
Finally, thank you to the Freya Holmér for providing inspiration for this project which was used in my International Baccalaurate Mathematics Internal Assessment (and that 7!1!1!). The video can be found here: https://www.youtube.com/watch?v=aVwxzDHniEw
This tool provides several key features for understanding and working with Bezier curves:
-
Interactive Drawing Tool
- Draw curves directly on a canvas
- Automatic fitting of Bezier curves to drawn points
- Real-time visualization of control points
-
Bernstein Polynomial Visualization
- View the individual Bernstein basis functions
- See the partition of unity property
- Interactive plots with customizable degree
-
Vector Visualization
- View control point influence through vector visualization
- See sequential vector addition at any point along the curve
- Interactive visualization of curve construction
-
Dark Mode Support
- Full dark mode support for all visualizations
- Configurable styling options
- Clone the repository:
git clone https://github.com/Wayrion/Bezier-Fitter.git
cd Bezier-Fitter
- Install required packages:
pip install -r requirements.txt
- Basic Usage:
python bezier_visualization.py
-
Interactive Drawing:
- Click and drag on the canvas to draw a curve
- Release to complete the drawing
- The tool will automatically fit a Bezier curve to your drawing
-
Viewing Visualizations:
- After drawing, the tool will show:
- Your original curve with fitted Bezier curve
- Bernstein polynomial basis functions
- Vector visualizations at t=0.5
- After drawing, the tool will show:
You can modify the following parameters in the script:
# Basic Configuration
BEZIER_DEGREE = 3 # Change the degree of the Bezier curve
BEZIER_RESOLUTION = 10000 # Adjust curve resolution
DARK_MODE = True # Toggle dark mode
# Visualization Settings
FIGURE_SIZE = (8, 6) # Change plot size
FONT_SIZE = 16 # Adjust font size
VECTOR_ALPHA = 0.4 # Modify vector transparency
- Start the program
- Click and drag to draw your curve
- Release to see the fitted Bezier curve
After drawing, you'll see:
- The original points and fitted curve
- Control points with annotations
- Mean Squared Error (MSE) of the fit
The tool will display:
- Bernstein polynomials for your curve's degree
- Vector influences at t=0.5
- Sequential vector addition visualization
- Python 3.8+
- NumPy
- Matplotlib
- SciPy
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Run
black
andisort
on your code - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.