![]() |
VOOZH | about |
What is a bezier curve?
So a Bezier curve is a mathematically defined curve used in two-dimensional graphic applications like adobe 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, modelling 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 has 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 endpoints 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
and
Now,
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 than 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 endpoints is the same as that of the vector determined by the 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 the SDL library to draw pixels on the screen. If you are on Debian system like ubuntu just runs following command to install SDL library.
Properties
Ex: We are given with four control points B0[1,0], B1[2,2], B2[6,3], B3[8,2], so determine the five points that lie on the curve also draw the curve on the graph.
Ans: Given curve has four control points hence it is a cubic bezier curve, So, the parametric equation of cubic bezier curve is
now, substitute the control points into the above equation so we'll get,
Let's assume five different values of t are {0, 0.2, 0.5, 0.7, 1}.
So, for t=0 the coordinate will be,
So, for t=0.2 the coordinate will be,
So, for t=0.5 the coordinate will be,
So, for t=0.7 the coordinate will be,
So, for t=1.0 the coordinate will be,
:
a) The degree of Bezier curve depends upon the number of control points associated with the corresponding curve, as the number of control points increases the polynomial degree of the curve equation also increases that make the curve equation very complex and harder to deal with.
Degree of curve = no. of control points - 1
b) One major disadvantage of using the Bezier curve is that they impart global control to the curve. Which means if the relative position of the curve changes the whole curve shape get changes. This makes it less convenient to use.
On changing any one of the control points relative position the whole curve shape get changes:
c) One more problem with Bezier is that its blending function never gets zero for any parameter irrespective of the degree of the curve.
sudo apt-get install libsdl2-dev
To build use
gcc fileName.c -lSDL2 -lm
Output
Move mouse when mouse position is b/w circle then only curve shape will be changed
Time Complexity : O(r) where r is the radius of the circle.
Space complexity : O(1)
References:
https://en.wikipedia.org/wiki/B%C3%A9zier_curve
https://www.tutorialspoint.com/computer_graphics/computer_graphics_curves.htm
https://www.math.ucla.edu/~baker/149.1.02w/handouts/bb_bezier.pdf