"Best" polyline from curve

I’m looking for a way to produce the “best” polyline from a curve, using a given number of points. GH has a Curve to Polyline component, but it determines the number of resulting points. I was able to come up with something using Galapagos by comparing the total lengths of the segments compared to the total curve length and it fits my naive expectation that the points should cluster near the areas of greatest curvature, but it takes quite a while, and I have a whole lot of curves. Here’s the Galapagos attempt:

best polyline.gh (9.1 KB)

1 Like

if you bake the new polyline and create curve you get different result compared to original

i tried with mesh

bake and convert to a curve than compare the new curve to the original one

But I’m not interested in reconstituting the original curve, just a polyline that approximates it.

what i mean if you want a polyline than the new curve must the same as the original one
if not so the polyline is wrong

best polyline_LD.gh (9.8 KB)
Here is a way it uses Curve to Polyline component (Legacy ?) with differents tolerances.

The multiple curves component


best polyline_multipleLD.gh (7.5 KB)

2 Likes

and here is a scripted approach that just takes a tolerance

splineToPolyline.gh (9.7 KB)

3 Likes

Thank you @laurent_delrieu and @lando.schumpich. Both methods are ingenious. Laurent, yours works well on any particular curve, but because of however Rhino determines the polyline, it does not have the effect I was hoping for. Small changes in the curve can have large results on point distribution, so when you connect them across curves with polylines, they are kind of jumpy. I am looking for a smoother transition that still has the points clustered near the areas with highest curvature…

Lando’s approach has the right look, but for multiple curves it gives different number of segments for the same tolerance. Laurent addressed this by searching over numerous tolerances, but again, perhaps this is not the right approach for my purpose. Maybe the “best” polyline is not what I need. I know, picky, picky, picky.

1 Like

Best polyline according to your description is the one that has the largest length for given number of points.
Here is one approach, slightly computing intensive but it is always like that with iteration based solution.
If noOfPoints is number of points that resulting polyline will have (e.g. 22) than:

  • we divide curve with higher number of points
  • start remove points whose damage is minimal (changing the length of polyline is minimal)
  • continue to remove points in the same manner until we reduce number of points to noOfPoints

We do it for different number division points and select final polyline whose length is maximum.
This code can be easily rewritten to use Parallel.For() in case better performance is needed.


best polyline_v02.gh (9.1 KB)

Radovan

Maximizing the total length is what I have Galapagos doing - but in its own way, and selecting from a multitude of polylines was similar to the approach of @laurent_delrieu. Like the above, your method works well on any particular curve but is also very sensitive to small changes, so the transition among many curves is not gentle. As I said earlier then, maybe “best” is not what I’m, looking for my purpose. I appreciate everyone’s response!

Did you try to loft the curve and then use this surface to calculate polyline ? I have already seen this trick to calculate tweens curves …

Yes, I tried lofting, hoping that the isocurves would look something like what I want but the problem is, you have to choose your curves carefully in order for it to look decent. I’m looking for something general. Lofting produces straight isocurves in the direction of the loft, so sometimes they crowd in too much; I was hoping for something more organic.

Edit - Laurent, I just tried your method using the isocurves from a loft and the results are not very different.

What’s your ultimate goal here? What problem are you applying this to?

How general? Are your curves always planar? Are they ever kinky? Are they similar in some way? It seems maintaining topology and similar spacing between similar curves is important. And also minimizing the number of control points. How many curves are you trying to match?

Producing a swarf milling toolpath for 5 axis machining has similar constraints, though only pairs of curves are needed. A tooltip/toolpath curve and a guide/orientation curve. I’ve used three methods for this before, each relevant for different kinds of geometry:

  • 1 Perpendicular plane intersections
  • 2 Division by equal numbers
  • 3 Closest point

Are any of these methods relevant to you?

What I’m trying to do is take a surface, say a stylized human figure, and slice it into horizontal contours, so yes, the curves would all be closed and planar but they could vary widely. Let’s say 50 contours. Each curve would be divided into the same number of points, using something like the logic up above. Points with the same index would then be joined forming a series of lines running vertically but clustering along the regions of greater curvature on the surface. If you imagine that my tween curves above are actually the projections of the contours, then, using the methods above, the lines on the figure would not flow gently down but would sometimes veer abruptly. This is what I’m trying to avoid. The lines themselves could be used to align some other objects.

I guess the problem with this is it becomes really inaccurate fast.
EvenIn the picture you posted above, the upper curves have a high curvature in the valley in the middle while the lower curves don’t have curvature in this part at all.
Since you can’t know how much your slices vary in curvature beforehand there has to be some kind of averaging.

  • you could average all point locations over all curves
  • you could identify the curve with the highest curvature values and use its parameters as a guide

Any other approach will yield division points varying wildly along the length of a curve, I think

1 Like

I took your suggestion about averaging and that seems to give a much smoother transition for Laurent’s and Radovan’s methods. For each curve, I average over the corresponding parameters and then used that to determine the points on all curves.

1 Like

Ok so i thought i’d take have a go at this and try out skeleton fattener

As you can see from the image, the number of contour curves varies between 1, 2 and 3 for this figure. Are you trying to make your solution general enough to cover these kinds of topological changes?

So you don’t actually need the lines? what are the rules with your object alignment?

human.contours.gh (25.9 KB)

I didn’t mean to complicate matters by suggesting a stylized human; all I meant was a vertical shape with some variation in the curvatures, that will give one contour for each level. Since unwanted variations from level to level occur along the length of the contour, having the figure symmetrical would be even better because then you’d only have to work on one half. Ultimately, I’m only interested in the vertical lines and not the contours, but the contours are initially needed to come up with the line distribution.

ok well i totally missed the mark then. You can get a pretty decent line flow out of the fattener mesh though…


human.contours.meshFlowgh.gh (29.7 KB)

1 Like

Nice, but not quite what I was looking for. Definitely worth keeping in mind though for the future. I have to schedule a play date with Fattener.

1 Like