3

In my situation I need to compare the length of 2 bezier curves. I do not need to compute the actual length of either curve. I merely want to cheaply compare which of the 2 is longer. My assumptions for this method are as followed:

Both Bezier curves to compare are same dimension(number of control points)

The dimension of the curves could be any number greater than 2

I need to output which of the 2 curves is longer (either if equal)

My original thought, was to just add the lengths of control points ie: distance(p0, p1) + distance(p1, p2) + distance(p2, p3)...

And It seems to work decently for lower order bezier curves. However I sure that this would not scale well in higher order curves.

I ended with a solution that adds the distance between each control point projected on the curve(basically take number of control points / index of point and using that value as T), and seems to work on some higher dimension curves.

I can't imagine I am the first person to want to do this, So to reiterate does anyone know of the right way to do this?

Community
  • 1
  • 1
Ender Doe
  • 162
  • 1
  • 10
  • 1
    Do you have some measurements or it is just your guess? How many points you expect at max? – Johnny Feb 22 '18 at 19:01
  • up to 60 and 70 points max, usually from 3 - 9. As for measurements the second case always worked from what I tested, but there are enough edge cases, that I am not entirely sure it will always work. – Ender Doe Feb 22 '18 at 19:03
  • 4
    Possible duplicate of [Cheap way of calculating cubic bezier length](https://stackoverflow.com/questions/29438398/cheap-way-of-calculating-cubic-bezier-length) – Johnny Feb 22 '18 at 19:09
  • 1
    It is different, This question is about which of 2 bezier curves is longer. the other question is about approximating length, and specifically cubic curves. – Ender Doe Feb 22 '18 at 19:12
  • 1
    You do realise that "which is longer" is the same question as "how do I compute the length", right? Once you know how to do that, just compare length(a) to length(b) and you have your answer. Now, as a professional programmer, my question would be "why cut corners before you know you need to?" Just use [someone else's code to compute length](http://pomax.github.io/bezierjs/#length) and fuss about "cheap approximation" only once your profiling shows a hotspot in length computation. – Mike 'Pomax' Kamermans Feb 23 '18 at 06:30
  • As secondary question: what do you mean with "higher order curves"? Are we talking genuinely nth order for n>3 (which in almost all situations are insane overkill and impossible to reasonably work with), or conventional poly-beziers (i.e. low order beziers, just linked up in a G1/G2 continuous fashion)? – Mike 'Pomax' Kamermans Feb 23 '18 at 06:32
  • This not for visual display. Yes where n > 3. My use case is quite unique. And I already know how to approximate the length of bezier curve. The application will be handling large amounts of n2-60 bezier curves and attempting to compare lengths as soon as possible. The objective of the application is specific this question, I asked exactly what I intended to. I'm am not using this for drawing 2d images. – Ender Doe Feb 23 '18 at 14:05

0 Answers0