I have try to solve the problem about the length of cubic bezier curve, in general it is cubic polynomial function

$a_pt^3 + b_pt^2 + c_pt + d_p$

I think the method is differentiate this function and it give the tangent of each component. Then integrate it

$\sqrt {(a'_xt^2 + b'_xt + c'_x)^2 + (a'_yt^2 + b'_yt + c'_y)^2 + ...}$

But then this became 4th degree polynomial in square root. When I need to integrate it I found out that it need elliptic integral. Which I don't understand it yet

And so I wonder that is it really possible to write the solution in programming language as a function. Because if it possible somebody would already write it in many language for calculate arc length of bezier curve in game engine

And if it impossible then why?


The title is misleading: solve arbitrary 4th degree polynomial should relate to the roots of this polynomial, and you don't need elliptic integrals for this.

To answer the real question (computing arc length using an elliptic integral): there are already implementations of elliptic integrals (as well as many over special functions) in several programming languages. See for instance the GSL for an implementation in C. In Fortran you will probably find something in one of the large libraries from the old days: SLATEC, CMLIB, MATH77, NSWC, PORT... However, I suspect that the computation may be too slow for a game engine, and a rough approximation may be used instead.

  • $\begingroup$ Thanks, I have fixed the title $\endgroup$ – Thaina May 14 '18 at 7:08
  • $\begingroup$ Also thank you for your information. But I know there was elliptic integrals function exist. What I don't know is why they have no function that wrap around Legendre's function with polynomial, convert the polynomial coefficient into that form and pass into Legendre. So I was doubt that if it might not possible $\endgroup$ – Thaina May 14 '18 at 7:19
  • 1
    $\begingroup$ @Thaina Probably because there are too many possible applications of elliptic integrals to consider implementing all of them, and computing an arc length is probably considered both too specialized and easy enough that if you want it, you just have to write a few lines of code. Maybe someone has done that, however, as I said, for games I would not be surprised if a rough approximation is used (numerical integration on a few points, for instance). $\endgroup$ – Jean-Claude Arbaut May 14 '18 at 7:46

If you search for "length of Bezier curve" on this site, you will find several helpful answers. In particular, one answer provides a link to this page, which has code for calculating the length.

This is basically just a numerical integration (quadrature) problem, and you can use whatever numerical methods you like.

According to this Wikipedia article, there is no closed-form formula for the integral (i.e. it can not be expressed in terms of elementary functions).

  • $\begingroup$ That's the point. I have already search about it and found out that most answer use approximation, not integral. And the name "elliptic integral" popped out sometimes. And that what I thinking that is that integral formula cannot really written programmatically. And why does it $\endgroup$ – Thaina May 15 '18 at 1:35
  • 1
    $\begingroup$ The usual approach is numerical integration. You use numerical methods to compute an approximate value for the integral. You have to use this aproach when there is no closed-form fomula for the integral (which is sually the case, in real life, outside of calculus homework problems). $\endgroup$ – bubba May 15 '18 at 14:07
  • 1
    $\begingroup$ See the Wikipedia article I linked to. If there was a closed-form solution. Also, please refer to this question: math.stackexchange.com/questions/155/… $\endgroup$ – bubba May 16 '18 at 15:31
  • 1
    $\begingroup$ The "solid proof" is going to be pretty complex. There's not much discussion on the Wikipedia page, but there is in the answers I linked to, it involves differential Galois theory. The first problem you have to face is how to define "closed form solution". If there was a closed form solution, it would be listed in all the standard tables of antiderivatives, and programs like Mathematica would be able to compute it. $\endgroup$ – bubba May 19 '18 at 0:15
  • 2
    $\begingroup$ You can try reading this: en.wikipedia.org/wiki/Risch_algorithm. If you're still not convinced, then there's not much more that I can do. $\endgroup$ – bubba May 19 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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