2

I have seen a few other questions/answers with the same title, but with different equations.

I’d like to find a general solution to $\int\sqrt{(\frac{dx}{dt})^2+(\frac{dy}{dt})^2}dt$

Specifically, I’d like to find the length of a 2D cubic Bézier segment expressed parametrically as $x=At^3+Bt^2+Ct+D$ and $y=Et^3+Ft^2+Gt+H$

Clearly,$\frac{dx}{dt} = 3At^2+2Bt+C$ and $\frac{dy}{dt} = 3Et^2+2Ft+G$ so for a Bézier segment, the integral would be $\int\sqrt{(3At^2+2Bt+C)^2+(3Et^2+2Ft+G)^2}dt$

That expands to the rather cumbersome $\int(\sqrt{9(A^{2}+E^2)t^4+12(AB+EF)ABt^3+(6(AC+EG)+4B^2+4F^2)t^2+4(BC+FG)t+C^2+G^2})dt$

Using the following substitutions:
$\alpha=9(A^{2}+E^2)$
$\beta=12(AB+EF)AB$
$\gamma=6(AC+EG)+4B^2+4F^2$
$\delta=4(BC+FG)$
$k=C^2+G^2$
the expression can be written as
$\int(\sqrt{\alpha t^4+\beta t^3+\gamma t^2+\delta t+k}) dt$
And that’s where I hit a brick wall. I have no idea how to proceed from here. I’ve been told that it will take an infinite series to express the solution, but I suspect that fewer than a dozen terms will be sufficient for computational accuracy.
Any advice is welcome.

  • You are nice saying that you hit a brick wall ! For me, it is at least concrete or armored steel. I would be very surprised to know that there is a closed form. Think about numerical integration instead. – Claude Leibovici Feb 18 '16 at 14:50
  • I don't believe that there is a closed form, and I would be happy with a series. This is for a computer program, and I already have a workable brute-force solution to the length problem that does not involve an integral, but depending on the parameters, it can result in adding fifty to a hundred or more terms. I'm hoping to find a solution that would give me a reasonable accurate answer in a dozen terms or fewer. – Logicrat Feb 18 '16 at 15:03
  • It would be a monster ! Moreover, the computations will be very expensive and you would not have any idea or control of the error. – Claude Leibovici Feb 18 '16 at 15:05
  • If it were a convergent series, I could continue computing until a term had an absolute value less than about 10^-7 or so. The brute force method I am using now is at least very good about controlling the margin of error. – Logicrat Feb 18 '16 at 17:27

1 Answers1

1

Just use a numerical integration procedure, like Gaussian quadrature. As usual, you can find easy-to-use (but often not-quite-optimal) code in the Numerical Recipes book.

There are Bézier curves for which you can compute the arclength exactly. They are called Pythagorean Hodograph (PH) curves, and have been studied extensively by Rida Farouki and others. But, in return for easy arclength calculation, you sacrifice a lot of shape flexibility.

There is no closed-form formula for the arclength of a general Bézier curve whose degree is greater than 2.

bubba
  • 43,483
  • 3
  • 61
  • 122