FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Discussion
   General Processing Discussion
(Moderators: fry, REAS)
   the meaning of bezier
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: the meaning of bezier  (Read 609 times)
benelek

35160983516098 WWW Email
the meaning of bezier
« on: Jan 11th, 2003, 3:11am »

how is the form of the bezier curve derived from its control points?
 
fry


WWW
Re: the meaning of bezier
« Reply #1 on: Jan 11th, 2003, 5:02pm »

my favorite explanation/tutorial on this subject:
http://mactech.com/articles/develop/issue_08/Reed_text.html
comes from a really crusty article in apple's old developer magazine. but it's nicely written and has a good introduction.
 
i have a pdf of this around somewhere, which is a little easier to read than the html version (may also be on the site, couldn't find it at a quick glance).  
 
the specifics can be seen in the "parametric equations, anyone?" which was an inset in the printed article but can be found at the very end of the html version. particularly useful is the explanation of subdividing in helping to understand how it works. (fwiw, this is not the same method used in p5, since it's too slow, but it's useful as a mental experiment)
 
benelek

35160983516098 WWW Email
Re: the meaning of bezier
« Reply #2 on: Jan 12th, 2003, 7:22am »

mm, cool.
 
great article! question: the author describes a bezier as following the parametric equation
 
f(t) = a(1-t)2 + 2bt(1-t) + ct2
 
where a,b,c are "points". perhaps i've forgotten a little of my mathematics. are these supposed to be the x-values, y-values, or some other coordinate measure of the point?
 
also, how do you create the curve when the two control points are not even on the same side of the curve? or when they're twisted about each other? in short, how do you merge two different beziers?
 
i made a small interactive example to help illustrate the many weird and wonderful ways of arranging control points of a 4-point bezier.
 
http://users.bigpond.net.au/schwartz/bezierExploration/applet/
 
-jacob
« Last Edit: Jan 12th, 2003, 9:12am by benelek »  
benelek

35160983516098 WWW Email
Re: the meaning of bezier
« Reply #3 on: Jan 12th, 2003, 9:27am »

ha! apparently, Mr. Pierre Bezier himself only died a few years ago: November 25, 1999, in fact.
 
welcome to the world of my spare-time research ;P
 
-jacob
 
Mike Davis

WWW
Re: the meaning of bezier
« Reply #4 on: Jan 12th, 2003, 11:59am »

You can break the equation into dimension-specific equations.  For example, replace a, b, c, d with ax, bx, cx, dx and apply the equation to get an x value, and do the same thing for y and z.  You can have curves in any dimension with the same equation.
 
To get the curves to have the same slope where they meet: the third point of the first spline, the last of the first spline and the first of the second spline (same point), and the second point of the second spline must lie along a line. (whew!)
 
fry


WWW
Re: the meaning of bezier
« Reply #5 on: Jan 12th, 2003, 6:03pm »

re: the parametric version..
 
t varies from 0 to 1 as you move along the path. the function is for a single dimension, so you'd run it for x and again for z. the a, b, c are the control point locations. the ones used in p5 are slightly different, in that 4 ctrl points are used.
 
also, to make this fast, a method called forward-differencing is used, which uses some linear algebra to approximate the curve in a pre-defined number of steps (20 of them in the case of p5). this is much faster than all the heavy math and multiple subdivisions needed for the parametric version.
 
the result is a 4x4 single matrix that is multiplied by the four control points, and then updated incrementally. the code from inside p5 follows:
 
Code:
 private void bezier_segment(float x1, float y1, float x2, float y2,  
    float x3, float y3, float x4, float y4) {
    float xplot1 = -0.142625f*x1 + 0.135375f*x2 + 0.007125f*x3 + 0.000125f*x4;
    float xplot2 =  0.014250f*x1 - 0.027750f*x2 + 0.012750f*x3 + 0.000750f*x4;
    float xplot3 = -0.000750f*x1 + 0.002250f*x2 - 0.002250f*x3 + 0.000750f*x4;
 
    float yplot1 = -0.142625f*y1 + 0.135375f*y2 + 0.007125f*y3 + 0.000125f*y4;
    float yplot2 =  0.014250f*y1 - 0.027750f*y2 + 0.012750f*y3 + 0.000750f*y4;
    float yplot3 = -0.000750f*y1 + 0.002250f*y2 - 0.002250f*y3 + 0.000750f*y4;
 
    vertex(x1, y1);
    for (int j = 0; j < 20; j++) {
 x1 += xplot1; xplot1 += xplot2; xplot2 += xplot3;
 y1 += yplot1; yplot1 += yplot2; yplot2 += yplot3;
 vertex(x1, y1);
    }
  }
 
mmuday

WWW
keysplines
« Reply #6 on: Jan 20th, 2003, 8:53pm »

I'm looking to create a way of doing keyspline-based transforms, a la SMIL.
 
Could you detail a little more your method of doing fast cubic spline calculations?
 
I'm interested in calculating y, given x and the x/y values of the four control points.
 
Any help or pointers would be appreciated!
 
Cheers,
-Mark
 
fry


WWW
Re: the meaning of bezier
« Reply #7 on: Jan 20th, 2003, 9:27pm »

if you need y given x, then you'll need to use the parametric equation, though i don't know it offhand for quadratic beziers (might be mentioned in the article).  
 
also, it's not really y you're looking for, it's f(x), which is different from a y coordinate on screen. you're describing a 1 dimensional function, not a 2D one like above.
 
the speedup comes when you can specify the number of segments, being evenly spaced increments for your x, which can be calculated incrementally like in the code sample i posted above.. but this is dependent on calculating all the values successively (i.e. if it's 20 increments, all 20 need to be calculated) because the value at each increment is dependent on the value at the previous increment.
 
mr.prufrock

WWW Email
Re: the meaning of bezier
« Reply #8 on: Feb 5th, 2003, 4:44pm »

I am looking for a way to check intersections between line and bezier-curve, and between 2 bezier curves... can anyone help?
 
I think there's a method called Bezier clipping, but I can't figure out how it works...
 

I grow old...I grow old
I shall wear the bottoms of my trousers rolled.
Koenie

170825270170825270koeniedesign WWW Email
Re: the meaning of bezier
« Reply #9 on: Mar 31st, 2003, 2:46pm »

I got this code, in which I used the equation stated in the article. It's not working properly. Can anyone tell me the workings of the equation?
 
Code:
size(800, 600);
 
int ax = 100;
int ay = 100;
int bx = 300;
int by = 100;
int cx = 200;
int cy = 50;
 
for (float i = 0; i < 1000; i+=0.01) {
  point(ax*(1-i)*2 + 2*bx*i*(1-i) + cx*i*2, ay*(1-i)*2 + 2*by*i*(1-i) + cy*i*2);
}

 
Koenie
 

http://koeniedesign.com
fry


WWW
Re: the meaning of bezier
« Reply #10 on: Mar 31st, 2003, 3:49pm »

i think you're equation is off.. aren't those suppose to be squares--as in power of 2--not multiply by two? i don't have it right in front of me..  
 
(checking the article now)  
 
actually, it's wrong in the html converted version.. the proper formula is:
 
f(t) = a(1-t)^2 + 2bt(1 - t) + ct^2
 
where ^2 means squared. so in p5, i think it would be:  
 
ax * sq(1-t) + 2*bx*t*(1-t) + cx * sq(t)
 
(something liek that, not looking at it very closely)
 
mr.prufrock

WWW Email
Re: the meaning of bezier
« Reply #11 on: Mar 31st, 2003, 5:10pm »

I think that equation will make a quadratic curve (1 control pt), if you want a cubic curve (2 ctrl pts), it might look like this:
 
a^3 * 3*(a^2)*b * 3*a*(b^2) * b^3
 
where a = t, b = (1-t), and 0<=t<=1
 
If I remember correctly, this form is called Bernstein Polynomials...
 

I grow old...I grow old
I shall wear the bottoms of my trousers rolled.
mr.prufrock

WWW Email
Re: the meaning of bezier
« Reply #12 on: Mar 31st, 2003, 5:27pm »

oops... my equation above is wrong. it should be like:
a^3*p1 + 3*(a^2)*b*p2 + 3*a*(b^2)*p3 + (b^3)*p4
 
the p1 to p4 are the 4 pts (2 end pts and 2 control pts).
 
sorry about that...
 

I grow old...I grow old
I shall wear the bottoms of my trousers rolled.
Koenie

170825270170825270koeniedesign WWW Email
Re: the meaning of bezier
« Reply #13 on: Apr 1st, 2003, 9:05pm »

ah, thanks a lot guys, it's working now. fry, you were right, the problem was in the equation. I uploaded the sketch: http://reaxis.koeniedesign.com/sketches/bezier.html
 
Koenie
 

http://koeniedesign.com
Pages: 1 

« Previous topic | Next topic »