Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Some Cubic Bézier Curve Questions

  1. Apr 17, 2007 #1
    I'm using a bézier curve in a Computer Game I'm working on that has four points:

    p0 (start point)
    p1 (directional helper for p0)
    p2 (directional helper for p3)
    p3 (end point)

    I nabbed the drawing formula from Wikipedia and it works fine.

    I have some problems though.

    I really need to obtain the length of the curve, accurate to within a pixel or two if possible. I also need to be able to take the length and convert it to t.

    This is necessary because fixed jumps in t (for example, incrementing it by 0.1 every frame) does not result in jumps of a fixed distance in pixels. If we were to plot dots along the curve at every 0.1 on t, the dots would not be equally spaced.

    My ultimate, evil, master plan is to obtain the length of my curve, divide the length by a certain number of steps, find t for each step, and then use t to plot the X and Y coordinates of objects which follow the curve.

    That'd be groovy, but I dunno how easy it'd be. Also, I managed to understand the Wiki's Bézier explanation, but I'm not too au fait with Mathematical Notation, so some explanations may be needed, heh.

    Bézier curves for dummies! Someone should so write that...
     
  2. jcsd
  3. Apr 18, 2007 #2

    StatusX

    User Avatar
    Homework Helper

    There are bezier curves of different orders, for example, the linear one takes two points and gives:

    [tex]\vec r(t) = (1-t) \vec x_1 + t \vec x_2 [/tex]

    the quadratic one takes three points and gives:

    [tex]\vec r(t) = (1-t)^2 \vec x_1 + 2t(1-t) \vec x_2 + t^2 \vec x_2 [/tex]

    and so on, so that your case is the cubic bezier curve.

    To find the length s of any curve, you just use:

    [tex] \frac{ds}{dt} = \left| \frac{d\vec r}{dt} \right| [/tex]

    So, for example in the linear case:

    [tex] \frac{d\vec r}{dt} = - \vec x_2 + \vec x_1 [/tex]

    so:

    [tex] \frac{ds}{dt} = |\vec x_1 -\vec x_2| [/tex]

    and the length of the Bezer curve is the integral of this function from 0 to 1, which in this case, since the function is constant, is just:

    [tex]s = |\vec x_1 -\vec x_2| [/tex]

    which makes sense, since the linear bezier curve is just the line segment from [itex]\vec x_1[/itex] to [itex]\vec x_2[/itex]. For higher order curves, the function will be more complicated, eg, for the quadratic, you'll have to integrate something like:

    [tex] \sqrt{ a x^2 + bx +c} [/tex]

    and for the cubic, there will be terms up to [itex]x^4[/itex] inside the square root. These can be done, but they're a mess. I'd suggest using mathematica or something. That or search online for somebody's who's done the work already.
     
    Last edited: Apr 18, 2007
  4. Apr 19, 2007 #3
    So... how do I find the length of my cubic Bézier curve?

    Might it be something like
    [tex] \sqrt{p_0 x^4 + p_1 x^3 + p_2 x^2 + p_3 x }[/tex]

    I'm assuming that the a, b and c vars in your quadratic example are the positions of the three points (which would need to be four for a cubic), but what is x?

    And also, if a, b and c in your quadratic suggestion are the positions of the points, how does this work with both the x AND y dimensions? How do I combine them? When I was originally drawing the Bézier Curve, I could simply copy the same formula and use it for the X and Y dimensions. But obviously, with something like length we want just one value coming out the other end.
     
  5. Apr 19, 2007 #4

    StatusX

    User Avatar
    Homework Helper

    You need to use calculus, which it seems like you're not that familiar with. Just try searching online for someone who's done it already. If you really can't find anything, maybe me or someone else will work it our for you, but it'll be pretty tedious and probably take a little time.
     
  6. Apr 19, 2007 #5
    Yeah, I'm not familiar with Calculus, lol. :tongue:

    I've googled and Wiki'd it, but all I can find are ways of aproximating it, and even then they're ill-explained or have too great a margin for error.

    But at the same time, I don't want you to spend a long time on it if that's what it would take. I made this post rather assuming it would be simpler than that.

    Thanks for your help all the same. I'm considering making a system to position dots along the curve, measure the straight lines between them, sum 'em up, and use that.
     
  7. Apr 19, 2007 #6

    hotvette

    User Avatar
    Homework Helper

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Some Cubic Bézier Curve Questions
  1. Bezier Curve Question (Replies: 1)

Loading...