Hello,
It’s one of my first posts here at this forum but I’m frequently hanging out at the grasshopper forum.
A while ago I made a plugin, called Advanced Surface Tools for Grasshopper.
My intention is to bring some very basic class-A surface functionality to Grasshopper in order to automate some surfacing tasks, which I frequently have to deal with when working with Icem Surf/Rhino -> high quality surface patterns and the ultimate goal: filleting of repetitive structures.
One of my main problems so far, besides all the hundreds of bugs :), is regarding accurate (<0.002mm) and fast approximation of splines to an array of points (or a curve). I need this for a lot of components.
Let’s see this example to get an impression of the problem:
An application example -> match a surface by projection:
I came up with 2 approaches which do have some pros and cons:
- Least square fitting with variable Degree:
Pro:
• quite accurate
• very fast
• constant spacing between cps
Cons:
• not stable for higher degree at some data problems start at degree 6, in this example at degree 11
• it can only approximate Beziers not Nurbs
- Recursive Approximation
Pro:
• Supports nurbs
• stable at higher degree
• spacing can be variable, because it tries to fit an existing spline to an reference (pts or curve)
Cons:
• not accurate enough -> problem here is measuring deviation fast enough for each iteration. So I limited measuring at the greville parameter.
• “Slower” in most cases, recursion aborts under a certain tolerance, but because of limited measuring this is not trustworthy. I limited to 2000 iterations. Now 4-12 ms at my maschine is not slow per se, but because this should be an core algorithm I think an recursive approach is last option.
Has somebody dealt with this problem?
Maybe someone has another or similar approach and is willing to share?
Is there may be a more stable least square approach with a nurbs extension?
My knowledge of advanced math is very limited, and I’m proud I made least square work with variable degree. So if
somebody can help improving this, it would be awesome.
Is there maybe a “hidden” rhinocommon method I haven’t found so far?
Any ideas in how to improve accuracy?
I have attached the code:
leastSquareVariableDegree_.gh (12.3 KB)
leastSquare.cs (3.1 KB)