What is a bezier curve?
So a Bezier curve is a mathematically defined curve used in two-dimensional graphic applications like abode illustrator,inkscape etc.The curve is defined by four points: the initial position and the terminating position i.e P0 and P3 respectively (which are called “anchors”) and two separate middle points i.e P1 and P2(which are called “handles”) in our example.Bezier curves are frequently used in computer graphics, animation, modeling etc.
How do we Represent Bezier Curves Mathematically ?
Bezier curves can be generated under the control of other points. Approximate tangents by using control points are used to generate curve. The Bezier curve can be represented mathematically as –
Where is the set of points and represents the Bernstein polynomials i.e. Blending Function which are given by –
Where n is the polynomial order, i is the index, and u/t is the variable which have from 0 to 1.
Let us define our cubic bezier curve mathematically.
So a bezier curve id defined by a set of control points to where n is called its order(n = 1 for linear , n = 2 for quadratic , etc.). The first and last control points are always the end points of the curve; however, the intermediate control points (if any) generally do not lie on the curve.
For cubic bezier curve order(n) of polynomial is 3 , index(i) vary from i = 0 to i = n i.e. 3 and u will vary from .
Cubic Bezier Curve function is defined as :
Cubic Bezier Curve blending function are defined as :
So we will calculate curve x and y pixel by incrementing value of u by 0.0001.
Properties of bezier curves
1. They always pass through the first and last control points.
2. They are contained in the convex hull of their defining control points.
3. The degree of the polynomial defining the curve segment is one less that the number of defining polygon point. Therefore, for 4 control points, the degree of the polynomial is 3, i.e. cubic polynomial.
4. A Bezier curve generally follows the shape of the defining polygon
5. The direction of the tangent vector at the end points is same as that of the vector determined by first and last segments.
6. Bezier curves exhibit global control means moving a control point alters the shape of the whole curve
NOTE:The following implementation uses SDL library to draw pixels on screen . If you are on debian system like ubuntu just run following command to install SDL library.
sudo apt-get install libsdl2-dev
To build use
gcc fileName.c -lSDL2 -lm
Move mouse when mouse position is b/w circle then only curve shape will be changed