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
This article is contributed by Palkansh Khandelwal
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Form the Cubic equation from the given roots
- Find cubic root of a number
- Program to check if N is a Centered Cubic Number
- Find the integral roots of a given Cubic equation
- Find Tangent at a given point on the curve
- Find normal at a given point on the curve
- Find nth term of the Dragon Curve Sequence
- Koch Curve or Koch Snowflake
- Implementation of a Falling Matrix
- Lychrel Number Implementation
- Fizz Buzz Implementation
- Dixon's Factorization Method with implementation
- Implementation of Wilson Primality test
- Implementation of Non-Restoring Division Algorithm for Unsigned Integer
- Implementation of Restoring Division Algorithm for unsigned integer
- Window to Viewport Transformation in Computer Graphics with Implementation
- Chinese Remainder Theorem | Set 2 (Inverse Modulo based Implementation)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ManasChhabra2