Check this out, I have a dense polyline that I want to smooth in Z values, but if I use 1 as smooth factor then I get lots of steps.
But if I change that to 0.9 then it smooths fine. What causes this?
Check this out, I have a dense polyline that I want to smooth in Z values, but if I use 1 as smooth factor then I get lots of steps.
But if I change that to 0.9 then it smooths fine. What causes this?
Smooth is on @pierrec 's list. What I can see is that at 1, smooth is simply moving the points so much that they level out in z completely. At 1 step you can clearly see this. Then the next step happens the same for the next set of points. This happens because your vertical line has no divisions in the z direction. If you would rebuild that curve to have multiple points on the vertical line this effect would not show.
I am not sure about that Gijs, I added the smooth to a script through:
for i in range(100):
polyline.Smooth(1)
And that works just fine.
Can you verify that?
EDIT: Oh, that smooth’s all directions… I’ll double check a bit more.
indeed, that works correctly. Smooth however seems to be the same as Curve.Smooth(), and that gives the same result when run through RhinoCommon.
now try polyline.Smooth(2)
Smooth
moves the (control) points of the curve at every step by moving them towards the average of the point before and the point after this point. When the slider is at 0, the point does not move, when the slider is at 1, the point moves all the way to the average point, when the slider is somewhere in between 0 and 1 the point moves by some amount 1-99% towards the average point.
So if you are starting from a polyline with points that are on just a few “levels”, one step of Smooth with factor 1 will move the two points on each side of a step to a new “average level”. The next step will add two new levels, but again two sets of two points will be at the same height; and so on for the next steps.
Using a factor strictly less than 1 (and possibly 0.5 or less) will work better in this case, and most other cases. We just leave it available as an option for potential special cases where that would be useful.
The RhinoCommon Polyline.Smooth
function is a reimplementation where the smooth factor used in the points movement is half of the input value. Probably because the results are too confusing when a smooth factor of 1 is used on a polyline.
You can use Curve.Smooth
to get access to the X Y Z options, but this will convert your poyline to a Curve.
Thanks, i know the principle behind smooth and so I wrote my own sollution to check if I get the same result, but my version works better. So please check the code and see if it has a bug.
I do wonder if using Rhino’s Smooth command with 1 (full strength) keeps a bit if the initial position as my smoother was stronger at 100 iterations.
It’s not a bug, it’s just what happens when the (simplistic) algorithm in Rhino’s Smooth
is applied to a polyline with a smooth factor of 1. My answer was an attempt to explain why this happens for a factor of exactly 1 but not .999. (And why the Polyline.Smooth()
method will give the same answer with a smooth factor of 2).
What is your version doing differently? There are many ways to smooth a curve, and many others to make it work better specifically on polylines, and Rhino is using a very simple algo in Smooth
. I’m not surprised another code gives a different answer. If it works better on most curves I could look into changing Smooth
.