"Best" polyline from curve

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.

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


so to clarify your question, something like this is the overall process? (im seeing it more as a landscape now than a human figure)

  1. point spacing not equal
  2. point distribution driven by curvature
  3. equal number of points on each row
  4. no abrupt changes between rows

v2.gh (165.1 KB)




You got it! And you don’t have to assume the curves are closed.

hmm i think 2 and 3 can contradict each other though. Is constant number of points more important than curvature adaptivity? if not, is this branching condition allowed?

Although the averaging method I used above looks OK, I thought maybe I was losing too much information by assigning all the parameters the same weight, so I added an exponential smoothing piece to @RadovanG’s component, with a damping parameter between one and zero. One gives the arithmetic mean and zero gives a totally unaveraged solution. It’s nice to play with, but when you do, it’s clear that anything other than the straight mean gives way to a lot of variation. I also increased the complexity of my surface to better reflect what I’ve got in mind and assumed a symmetrical shape.

best polyline continued.gh (18.1 KB)

Branching is forbidden!!

is this similar to your idea?

This method adds points when necessary, so the actual number is unknown until the end. It looks like you can tweak the total number by adjusting a tolerance, but that will only work for a particular curve. I guess you can do that for every curve in turn, so they all end up with the same number of points, which is the goal, but that’s beyond my skillset.

1 Like