Some Cubic Bézier Curve Questions

  • Thread starter RagingPineapple
  • Start date
  • Tags
    Cubic Curve
In summary, the conversation discusses the use of a bézier curve in a computer game, with four points: p0 (start point), p1 (directional helper for p0), p2 (directional helper for p3), and p3 (end point). The speaker mentions obtaining the length of the curve and converting it to t, as well as their ultimate plan to use t to plot coordinates along the curve for objects to follow. They also discuss different orders of bezier curves and how to find the length of a curve using calculus. The conversation ends with the speaker considering a different method involving positioning dots along the curve and measuring the straight lines between them.
  • #1
RagingPineapple
21
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
  • #2
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:
  • #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.
 
  • #4
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.
 
  • #5
Bézier curves for dummies! Someone should so write that...

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.
 

1. What is a Cubic Bézier Curve?

A Cubic Bézier Curve is a type of curve used in computer graphics and mathematical modeling. It is defined by four control points that determine the shape and direction of the curve.

2. How do you create a Cubic Bézier Curve?

To create a Cubic Bézier Curve, you need to specify the starting and ending points of the curve, as well as two control points that determine the shape and direction of the curve. These points can be defined using coordinates or relative values.

3. What is the difference between a Cubic Bézier Curve and other types of curves?

A Cubic Bézier Curve is different from other types of curves, such as quadratic Bézier curves or arcs, because it allows for more control over the shape and direction of the curve. It also has the ability to create more complex and smooth curves.

4. How is a Cubic Bézier Curve used in computer graphics?

Cubic Bézier Curves are commonly used in computer graphics to create smooth and curved lines, such as in vector graphics and animations. They are also used in design software, such as Adobe Illustrator, for creating curves and shapes.

5. Are there any limitations to using Cubic Bézier Curves?

While Cubic Bézier Curves offer a lot of control and flexibility, they do have some limitations. For example, they can only create curves that are continuous and smooth, and they may not accurately represent more complex shapes or curves with sharp angles.

Similar threads

Replies
4
Views
2K
Replies
1
Views
3K
Replies
8
Views
3K
Replies
2
Views
3K
  • General Math
Replies
5
Views
3K
Replies
2
Views
4K
Replies
5
Views
6K
  • General Math
Replies
11
Views
12K
Replies
1
Views
3K
Replies
23
Views
13K
Back
Top