# Thread: Bezier Curves where y = f(x)

1. ## Bezier Curves where y = f(x)

It seems that Bezier curves are usually defined parametrically where

y = f1(t)
x = f2(t)

I'm trying to code non-parametric Bezier curves. I would like to have y explicitly in terms of x. Something like

y = f(x)

Has anyone seen anything on Bezier curves written in this form?

2. If you plan on writing it in 3D you need to have at least 2 variables that the function depends on. f(x,t) = y or something of the like. You can't draw a 3D graph with no concept of time, unless maybe you shift everything with respect to the same time, but even then it is technically having 2 variables. I didn't make bezier curves exactly, but I made a parametric equation plotter. If you want to take a look at it the link is in my signature.

3. Thanks, but I'm just trying to create 2D curves.

4. Perhaps not the easiest reading ever, but:
http://en.wikipedia.org/wiki/Bezier_curves

--
Mats

5. I've as far as the Wikipedia page. I have an idea of how to do this, but I have to find the roots of a cubic equation, which is something I'm not looking forwards to doing.

6. You can't do y = f(x) for bezier curves because for a given x value you can have multiple y values.

7. There are several types of bezier curves.

After examining this on wikipedia and seeing the 'classroom' formula there is actually a simpler solution when it comes to programming them.

If you notice a bezier curve with 3 control points is quite simple. Take arbitrary control points A and C and an arbitrary control point B. The curve is created by first finding a point between A and B and finding a point between B and C using linear interpolation. Now draw a line between those points and interpolate on it the same distance as you did to find the two intermediate points. You need some type of time delta here though in order to draw the final curve.

Code:
```D3DXVECTOR2 A;
D3DXVECTOR2 B;
D3DXVECTOR2 C;

D3DXVECTOR2 betweenAB;
D3DXVECTOR2 betweenBC;

float lerp = 0.0f;

while (lerp <= 1.0f)
{
D3DXVec2Lerp(&betweenAB,A,B,lerp);
D3DXVec2Lerp(&betweenBC,B,C,lerp);

D3DXVec2Lerp(&curvePoint,&betweenAB,&betweenBC,lerp);

lerp += 0.2f;
}```
A 1D linear interpolation is a simple function:

Code:
```float lerp(float start,float end,float lerp)
{
return start + lerp * (end - start);
}```
I used D3DX here because it has overloaded the various operators so they work on 2D, 3D, and 4D vectors.
The bezier curve will trace out over time as the line between the computed points at time T between A and B and B and C changes.
You can extend this to cubic bezier curves as well and pretty much any order of curve and it just requires more linear interpolations.

I have never tried the 'school room' equations for the curves in code so I have no data as to whether or not the tried and true formulas are slower or faster in code. I would venture to guess the series of linear interpolations would win in the end. I use this in one version of my camera system that computes a new 'control point' between two camera positions. I then use this to run the camera's path along the bezier curve created by the 3 points.

But as has been said already without time there are no Bezier curves. There is no way to trace a curve from A to B without time and in fact there is no way to trace a line from A to B without time. A line is a simple bilinear interpolation between A and B and a curve with 3 points is 3 bilinear interpolations along 3 lines using the same coefficient for interpolation.

8. Here is a page that describes basically what Bubba said: http://graphics.cs.ucdavis.edu/educa...ier-Curve.html

The page does it for the t=0.5 condition but it can be done for at 0<= t <= 1.

When I did Bezier curves I found the equations much easier to deal with. But of course for the programs I just used the OpenGL function to create them for me.

9. Interesting. I did not realize that my approach was an actual approach used elsewhere in graphics. I derived my approach from looking at the animations on wikipedia which led me to the overall idea since I am extremely familiar with interpolations.

10. Originally Posted by thetinman
It seems that Bezier curves are usually defined parametrically where

y = f1(t)
x = f2(t)

I'm trying to code non-parametric Bezier curves. I would like to have y explicitly in terms of x. Something like

y = f(x)

Has anyone seen anything on Bezier curves written in this form?
Sure.. think about what happens if f2(t) = t.

You can rotate the parametric form until f2(t) = a*t+b, but this is not always possible because the curve might become multi-valued for some values of x, which is pretty much why these things are specified parametrically in the first place.

EDIT: More generally, you can solve x = f2(t) for t in terms of x, then substitute this into f1(t). However your result will include roots which might be multi-valued.

11. The curve I need won't be multi-valued for a given value of x. I will need to have at least a cubic Bezier curve though, which means that f2(t) != t.

12. Originally Posted by Bubba
There are several types of bezier curves.
Do you mean different types aside from quadratic, cubic, quartic, etc? Do they have names?

Popular pages Recent additions