This project is an introductory look into the math of Bezier curve's with an aim to create a N degree Bezier curve tool using C++ (SDL2) . Some useful resources to follow will be
- The Beauty of Bézier Curves
- The Math Behind Font Rasterization | How it Works
- Coding Bézier Curves — Day 1
Created: July 22, 2022 11:24 PM
Given two points connected by a line segmet , a point P in the line segment is reprsented by a single value t , which is like a fraction parameter , and tells us where in the line segement P is .
We call it linear interpolation or lerp in short
Consider that now we have two such lines and two linear interpolation points in them , now when we connect them , they form another line segment ( the blue color line in the image )
Now this blue lines midpoint traces what is called as the quadratic bezier curve , now why just stop at 2 , what if we did this process for one other iteration , this is called as the cubic bezier curve.
The cubic bezier curve is the most common form of the bezier curve used.
This idea of iteratively using linear interpolation function to generate bezier curves is called as the De Casteljau’s Algorithm.
Now lets dive into the math a little bit.
Lets take the above cubic bezier curve
This is a visualization , think of these points as vectors from the origin , now the polynomial generated by iteratively applying linear interpolation acts like weights , and they are given as graph in the right image , so the resultant curve is due to the weighted sum of vectors , whose weight is determined by this cubic polynomial.
This is called the Bers
This is called the Berstein Polynomial version of Bezier curves.
Now just imagine this, what happens when we take the derviative of the above function !!
We get the tangent vector at each point , the derivative of the cubic bezeir curve is in itself a quadratic bezeir curve.
Now why is this important , with this we can get both the tangent and normal directions at each point . As soon as we have the tangent and normal vectors , we can now have a local coordinate system , which can give us offset points which are useful in generation of roads in 3D
Now what happens if we differentiate it again ..
and again to get jerk.
Now using the velocity and acceleration we can calculate the curvature given by
its the reciprocal of the radius of the oscillating circle
This is an interesting case where the curvature changes from negative to positive , the point of change is called as the inflection point.
Another use of bezier curve stems from the fact that they can generate bounding boxes around them
The points that define the box are given by the roots of the derivative ( that is points of maxima and minima for the curve )