Skip to content

An introductory project on understanding the math behind Beziers curves , and implementation of De Casteljau’s Algorithm

Notifications You must be signed in to change notification settings

jayantakumar/BezierCurves

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

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

Bezier curves

Created: July 22, 2022 11:24 PM

Screenshot 2022-07-22 at 11.24.51 PM.png

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

$$ P = (1-t)P_0 + tP_1 $$

Screenshot 2022-07-22 at 11.27.41 PM.png

Screenshot 2022-07-22 at 11.27.57 PM.png

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 )

im.gif

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.

im.gif

The cubic bezier curve is the most common form of the bezier curve used.

De Casteljau’s Algorithm

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

Screenshot 2022-07-22 at 11.37.29 PM.png

$$ P(t ) = P_0(-t^3+3t^2-3t+1)+P_1(3t^3-6t^2+3t)+P_2(-3t^3+3t^2)+P_3(t^3) $$

Screenshot 2022-07-22 at 11.39.58 PM.png

Screenshot 2022-07-22 at 11.40.14 PM.png

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

im.gif

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.

im.gif

Now using the velocity and acceleration we can calculate the curvature given by

$$ \kappa = \frac{det(P'P'')}{|P'|^3} $$

its the reciprocal of the radius of the oscillating circle

im.gif

This is an interesting case where the curvature changes from negative to positive , the point of change is called as the inflection point.

Bounding box

Screenshot 2022-07-22 at 11.59.51 PM.png

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 )

About

An introductory project on understanding the math behind Beziers curves , and implementation of De Casteljau’s Algorithm

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages