Can we write elliptic integrals to integrate arbitrary 4th degree polynomial as a programming function?

408 Views Asked by At

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?

2

There are 2 best solutions below

3
On

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.

8
On

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).