This project provides an interactive visualization of cubic Bézier curves using Flutter. The application allows users to modify control points and endpoints, view the resulting curve, and understand how Bézier curves work by displaying their mathematical equations in real-time.
This project is inspired by concepts learned in Math 330, Section 3.5 on Bézier Curves, taught by Prof. Wanda Strychalski at Case Western Reserve University. It demonstrates the mathematical properties and computations behind Bézier curves while offering a UI to explore them dynamically. Cool 🚀
A Bézier curve is a parametric curve frequently used in computer graphics, animations, and related fields to model smooth curves. In this project, we focus on cubic Bézier curves, which are defined by:
-
Two endpoints:
$(x_1, y_1)$ and$(x_4, y_4)$ . -
Two control points:
$(x_2, y_2)$ and$(x_3, y_3)$ .
The control points influence the direction and curvature of the Bézier curve but are not points on the curve itself.
The cubic Bézier curve for
where:
This parameterization ensures a smooth curve between the endpoints, influenced by the control points' relative positions.
- The slopes at the endpoints are controlled by the vectors connecting the endpoints to their respective control points.
- The curve is sensitive to user input through the scaling of derivatives by a factor of 3, enhancing its responsiveness to control point adjustments.
- Interactive Curve Manipulation: Users can drag the control points and endpoints to dynamically update the curve.
- Real-Time Display of Equations: The Bézier curve equations are displayed and updated as users modify the points.
- Control Point Editing: Users can click on control points to input precise coordinates, with validation to ensure proper input.
- Grid and Axes: A grid and x/y axes help users visualize the curve in a Cartesian coordinate system.
Points.dart
: A class representing a point withx
andy
coordinates.BezierComputation.dart
: Contains the logic to compute Bézier curve coefficients and evaluate points on the curve.BezierCurve.dart
: A class that models a Bézier curve using four points and offers methods to generate points along the curve.BezierCanvasPainter.dart
: A FlutterCustomPainter
that draws the Bézier curve, grid, axes, and control points on a canvas.screen.dart
: The main UI screen that provides an interface for interacting with the curve.
The Bézier coefficients
Given a parameter
- Dragging Points: Users can drag endpoints and control points to reshape the curve. The
GestureDetector
component handles user input, updating the curve accordingly. - Manual Input: By clicking on a control point, users can manually input coordinates, with validation to ensure only numerical values are accepted.
Consider an example Bézier curve defined by the points:
-
Start Point:
$(-100, 0)$ -
Control Point 1:
$(-50, -50)$ -
Control Point 2:
$(50, 50)$ -
End Point:
$(100, 0)$
The curve will be drawn centered on the origin, with the control points influencing the shape. Users can modify these points to observe changes to the curve and corresponding equations.
- Bézier curves are commonly used in font design, graphic animations, and modeling smooth paths.
- This project illustrates the underlying mathematics and provides an intuitive way to understand how control points influence curve shape.
- Prof. Wanda Strychalski: For teaching the foundational concepts of Bézier curves in Math 330 at Case Western Reserve University.
- Math 330 Material: Reference material from Section 3.5 on Bézier curves, explaining the derivation and properties of cubic Bézier curves.