Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm not sure if this is more of a math.stackexchange.com (or physics??) question, but here it is:

How can I find out the distance traveled by a Bezier Curve? For example, the distance traveled by a Linear Bezier Curve is:

distance = sqrt(pow(x[1] - x[0], 2) + pow(y[1] - y[0], 2));

But what of a Quadratic, Cubic, Nth-Degree Bezier Curve?

My goal is to figure out the "resolution" beforehand, so I don't have to waste time checking if the next point is touching the previous point.

share|improve this question
1  
You should reword the question to refer to the length of the curve, that is a much more straightforward (and searchable) term. – Sparr Nov 28 '10 at 11:34
i suggest posting this on math, i'm sure some clever face over there will give you the answer in one of them clever web fonts :p – Tor Valamo Nov 28 '10 at 17:27
@Tor I did (yesterday), but I've been told it's very complicated, and hence unpractical. [ math.stackexchange.com/q/12186/2736 ] – muntoo Nov 28 '10 at 21:08

2 Answers

up vote 4 down vote accepted

For cubic ones a simple way is to split up the curve into N segments and then compute the distances between each segment and sum those up, as Williham said, this in non trivial, but diving is a rather simple approach.

Also, as soon as you need more than just the length (e.g. get a point at 30% of the curves length), arc-length parameterization will come into play, so you should take a look at that.

I posted a fairly long answer on one of my own questions about béziers which explains that in simple code:
Moving ships between two planets along a bezier, missing some equations for acceleration

share|improve this answer
I'm doing this for the LEGO Mindstorms NXT, which has a really weak processor (48Mhz), so I need as much speed as possible. I'll take the dividing approach to conserve some speed, and get it accurate enough (for "non-realtime" rendering). I also have a option in which you can set the value of 1.0/t (called resolution), so that's for "realtime" (which is at best 10fps on the slow NXT). Every iteration, t += resolution, and a new point/line is drawn. Anyways, thanks for the idea. – muntoo Nov 29 '10 at 0:58

While this question is a better fit for math.stackexchange.com, the short version is that except for trivial and/or degenerate cases; solving for the exact length of an arbitrary bezier curve is non-trivial.

If you can make do with an approximation, quadratic curves are relatively easy to deal with (source), cubic curves less so.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.