Length of quadratic bezier curves

Started by
2 comments, last by Wasting Time 17 years, 5 months ago
I am devloping some custom shapes for one editing software. Just now I have developed the pillow using 12 bezier curves with 3 control points. But for some reason when I am setting the triangles inside the model I need to calculate the length of the quadratic bezier curve. Is there any way to do this? How to calculate the length of the bezier curve?
MOV AL, 0x00MOV AL, ME
Advertisement
If you can make do with an approximation, you can just sample intervals on the curve (increase the number of intervals until the length of the largest interval is < some epsilon). The sum of the lengths will give you a decent approximation given a small enough epsilon.
It would be very hard to calculate exactly the length of the curve.

Using a bit of calculus and given information about the three points:
Given your three points:
P0=(a, b)
P1=(c, d)
P2=(e, f)

and curve given by:
B(t) = (1-t)2P0 + 2t(1-t)P1 + t2P2 from t = 0 to t = 1

The length of the curve is given by: L = 2*∫√((at - ct - a + c + et)2 + (bt - dt - b + d + ft)2) from t = 0 to t = 1.

If you are familiar with calculus and are, somehow, able to evaluate this integral using symmetry, etc. Then the answer you would get out, should be exact, barring any sort of numerical-accuracy errors that occur along the way.

However, since you don't need to generate the lengths at run-time(I think), you could just write a program that calculates the value using an approximate integration technique like Simpson's Rule.

POST-THOUGHT: Given your situation, I think it would be better to it LachlanL's way, because it is not the actual length of the curve you are most probably looking for, but the length of the curve drawn to the screen.
"..."
If you write the curve as X(t) = A + B*t + C*t^2, where A, B, and C are 2-tuples, then the derivative is X'(t) = B + 2*C*t. The t-value is in [0,1], but you might want only the length of a section of the curve, say, t in [t0,t1]. The arc length is

L(t0,t1) = integral(t0,t1) |X'(t)| dt

The length of the derivative may be written as |X'(t)| = sqrt(a+b*t+c*t^2), where a = B.B, b = 2*B.C, and c = 4*C.C (the "." means dot product). So you need to compute the indefinite integral of sqrt(a+b*t+c*t^2). This may be done in closed form,

I(t) = (2*c*t+b)*sqrt(a+b*t+c*t^2)/(4*c) + log(2*sqrt(c)*sqrt(a+b*t+c*t^2) + 2*c*t + b)*(4*a*c-b^2)/(8*c^{3/2})

where "log" is the natural logarithm. The length is then L(t0,t1) = I(t1) - I(t0).

This topic is closed to new replies.

Advertisement