Some Cubic Bézier Curve Questions

  • Context: Undergrad 
  • Thread starter Thread starter RagingPineapple
  • Start date Start date
  • Tags Tags
    Cubic Curve
Click For Summary

Discussion Overview

The discussion revolves around calculating the length of a cubic Bézier curve in the context of a computer game. Participants explore methods for obtaining the curve's length accurately and how to convert that length into parameter values (t) for plotting points along the curve. The conversation includes technical explanations, challenges faced by the original poster, and suggestions for further exploration.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • The original poster describes the need for an accurate length measurement of a cubic Bézier curve to ensure consistent spacing of plotted points along the curve.
  • One participant explains the general formula for calculating the length of curves using calculus, mentioning that the cubic Bézier curve involves more complex integrals compared to linear and quadratic cases.
  • The original poster questions how to derive the length of the cubic Bézier curve and expresses confusion about the variables involved in the formula.
  • Another participant suggests that the original poster may need to search for existing resources or examples online to find a solution, indicating that the process could be tedious.
  • The original poster acknowledges their lack of familiarity with calculus and expresses frustration with the difficulty of finding clear explanations or methods for approximating the curve length.
  • A later reply provides a link to a Google search for resources related to the length of Bézier curves, suggesting that there may be useful information available online.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a specific method for calculating the length of the cubic Bézier curve. There are multiple viewpoints regarding the complexity of the calculations and the need for further resources.

Contextual Notes

The discussion highlights limitations in the original poster's understanding of calculus, which may affect their ability to follow the technical explanations provided. There is also uncertainty regarding the integration process for calculating the length of the cubic Bézier 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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 11 ·
Replies
11
Views
13K
  • · Replies 5 ·
Replies
5
Views
7K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 23 ·
Replies
23
Views
14K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 12 ·
Replies
12
Views
11K