Some Cubic Bézier Curve Questions

  • Thread starter Thread starter RagingPineapple
  • Start date Start date
  • Tags Tags
    Cubic Curve
AI Thread Summary
The discussion revolves around the challenges of calculating the length of a cubic Bézier curve for a computer game. The user seeks a method to accurately determine the curve's length to ensure consistent spacing of points along it, as fixed increments in the parameter t do not yield equal pixel distances. They express a need for clearer explanations of the mathematical concepts involved, particularly in relation to integrating the curve's derivative. Suggestions include using calculus or software like Mathematica for precise calculations, while also considering approximation methods. The user is exploring alternative strategies, such as measuring distances between plotted points along the curve.
RagingPineapple
Messages
21
Reaction score
0
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 don't know 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...
 
Mathematics news on Phys.org
There are bezier curves of different orders, for example, the linear one takes two points and gives:

\vec r(t) = (1-t) \vec x_1 + t \vec x_2

the quadratic one takes three points and gives:

\vec r(t) = (1-t)^2 \vec x_1 + 2t(1-t) \vec x_2 + t^2 \vec x_2

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

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

\frac{ds}{dt} = \left| \frac{d\vec r}{dt} \right|

So, for example in the linear case:

\frac{d\vec r}{dt} = - \vec x_2 + \vec x_1

so:

\frac{ds}{dt} = |\vec x_1 -\vec x_2|

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:

s = |\vec x_1 -\vec x_2|

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

\sqrt{ a x^2 + bx +c}

and for the cubic, there will be terms up to x^4 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:
So... how do I find the length of my cubic Bézier curve?

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

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.
 
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.
 
Bézier curves for dummies! Someone should so write that...

Yeah, I'm not familiar with Calculus, lol. :-p

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.
 
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Suppose ,instead of the usual x,y coordinate system with an I basis vector along the x -axis and a corresponding j basis vector along the y-axis we instead have a different pair of basis vectors ,call them e and f along their respective axes. I have seen that this is an important subject in maths My question is what physical applications does such a model apply to? I am asking here because I have devoted quite a lot of time in the past to understanding convectors and the dual...
Back
Top