0
votes

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.

  • user input an implicit function, let's say y=2x^3.
  • calculate control points (don't know how to do)
  • draw bezier curve (done)
  • next function

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

1
Calculating the starting and ending points requires you to limit the range of the function. In the example you provided, x and y are both unbounded.Mark Ransom
Yes, I forgot to mentioned that, I will add it nowFunnyFunkyBuggy
Now it should be trivial to calculate the first and last points of the Bezier. Are you trying for a single curve, or a piecewise approximation?Mark Ransom
I think single curve for nowFunnyFunkyBuggy
Actually, my main concern is that I have no idea how to find the control pointsFunnyFunkyBuggy

1 Answers

1
votes

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