0

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

FunnyFunkyBuggy
  • 495
  • 1
  • 7
  • 21

1 Answers1

1

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
Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • In your general form, you wrote "y = a + b * x + c * x^2 + d * x^4". Should it be "y = a + b * x + c * x^2 + d * x^3" ? – FunnyFunkyBuggy May 10 '16 at 05:19
  • So, in your case you assumed x is ranged from 0 to 1? If I have other range of x, say 0-2, how should I implement your method? – FunnyFunkyBuggy May 10 '16 at 05:21
  • Yep, I missed that `^4`. Should be `^3`. Neither `x` nor `t` is constrained to the range `[0, 1]`. You can evaluate the Bezier curve with parameters that do not lie in this interval. If you want to keep this interval, you have to find a different parameterization. – Nico Schertler May 10 '16 at 11:05