mathbeziercurves

How to calculate control points for a bezier curve with a given implicit function?


I am trying to write a program to draw a bezier curve segment implementing the knowledge from my textbook. I wanted to try making a drawing program to draw something using implicit functions. I want my program to work as follow.

Theoretically, I can draw the curves by direct substitution, but I might do some modifications to the curve and I want to implement what I have learnt, so, I wanted to do it wisely(direct substitution seems dumb).Thz^^

Edit 1 : Let's assume the boundaries were provided by the user


Solution

  • The first step is generating a parameterized expression for the curve. The given example can be transformed very easily:

    c(t) = (t, 2 * t^3)^T
    

    Now express this curve in Monomial basis:

    c(t) = / 0  1  0  0 \ * (1, t, t^2, t^3)^T
           \ 0  0  0  2 /
         = C * M(t)
    

    In this expression, the first matrix C is the coefficient matrix. All we need to do is transform this matrix to Bernstein basis. The matrix that transforms Monomial basis to Bernstein basis is:

           / 1 - 3t + 3t^2 -  t^3 \   / 1 -3  3 -1 \    /  1  \
    B(t) = |     3t - 6t^2 + 3t^3 | = | 0  3 -6  3 | *  |  t  |
           |          3t^2 - 3t^3 |   | 0  0  3 -3 |    | t^2 |
           \                  t^3 /   \ 0  0  0  1 /    \ t^3 /
    

    This equation can be inverted to get:

           / 1   1   1   1 \
    M(t) = | 0  1/3 2/3  1 | * B(t)
           | 0   0  1/3  1 |
           \ 0   0   0   1 /
    

    Substituting this into the curve equation, we get:

    c(t) = C * M(t)
               / 1   1   1   1 \
         = C * | 0  1/3 2/3  1 | * B(t)
               | 0   0  1/3  1 |
               \ 0   0   0   1 /
    

    The first matrix product can be calculated:

    c(t) = / 0  1/3  2/3  1 \ * B(t)
           \ 0   0    0   2 / 
    

    And this gives you the control points for the Bezier curve:

    p0 = (0, 0)^T
    p1 = (1/3, 0)^T
    p2 = (2/3, 0)^T
    p3 = (1, 2)^T
    

    This very procedure can be applied to any polynomial curve.

    The general solution for an equation in the form

    y = a + b * x + c * x^2 + d * x^3
    

    is:

    p0 = (0, a)^T
    p1 = (1/3, a + b/3)^T
    p2 = (2/3, a + 2b/3 + c/3)^T
    p3 = (1, a + b + c + d)^T