mathgeometrybezier

Bezier curve arc lengths


I have some code that calculates the length of bezier curves. I'm trying to write unit tests for it. But other than the trivial cases (straight line beziers) I don't know any actual correct values for the lengths. I've looked online and been unable to find any.

Does someone have this info? I'm looking for a link to a table with a few rows containing four bezier control points and then a length, or possibly create a couple of beziers in a drawing program that calculates the length (I've tried using blender and inkscape to get this info and they're quite complicated).

Solution. Download pomax's bezier javascript code from here and then open this html in a web browser:

<html>
<head>
<script src="bezier.js"></script>
</head>
<body>
<script>
curve = new Bezier([4.0, 0.0,  4.0, 
                    4.0, 0.0,  12.0,
                   16.0, 0.0,  12.0,
                   16.0, 0.0,  4.0]);

document.write(curve.length());
</script>
</body>
</html>

Solution

  • If you want actual arc lengths to test against, you'll have to implement your own bezier length code by doing something like this, computing arbitrarily accurate numbers based on calculating the Legendre-Gauss quadrature (you don't have to understand how it works, although the video link shows you that it's actually ridiculously simple. Consequently, implementing it is thankfully really easy).

    Another option is to rely on something like wolframalpha.com or Mathematica (which is free if you own a Raspberri PI): set up a random curve, and make them compute the length "properly", then use that result as reference value in your unit tests.