# Machine learning and curve fitting

Hello all

I am about to embark on processing some scan data. My goal is to extract some curves from the scan by slicing the point cloud. The problem is I get very dirty data, which I need to drastically simplify. Trying to fit a curve through all the points, and then simplifying, seems very tedious and “old-school”.

A more modern approach would be to select the points, enter the desired point count and curve degree, and have an algorithm come up with the best fit curve. This seems an ideal task for machine learning. Has anyone tried this yet? Any plugins to this already?

Cheers,

Tom

Hello - `Rebuild` does this, but there is no tolerance input.

-Pascal

Hi Pascal

Well, you still need to run a curve through the original unsorted points, and given how scans are put together (multiple scans overlaid) there is no guaranty they are ordered. I just tried running a curve through the points, and it doubles back on itself in several places, which makes the result unusable for a rebuild. Trying to select the points in order isn’t an options (>4500 points).

I suspect that iteratively coming up with geometry isn’t in Rhino’s DNA, but with the increasing availability of machine learning I wonder how long that can be the case…

Polynomial regression was invented 200 years ago. It is not a task of the ML but of the statistics.

Dodo has a non-linear least squares algorithm and maybe there is another GH plugin with more advanced regression tools. I suppose you could fit a line (Line through points in Rhino, Fit line in Grasshopper) and measure the error of each point, smooth this distribution and map the result to each control point to move them to fit the curve. Or also you can use Galapagos to minimize the error of a initial linear curve with some control point movement constraints. And also you could sort the points using one or several fitted lines.

Hi Dani

Well, firstly, large chunks of ML these days are simply statistics on steroids, so in a way I agree with you. The problem is I’m not looking for a single polynomial or even a piece-wise polynomial, but a NURBs curve with control points. So doing polynomial regression isn’t that helpful, or at least not directly.

Second, imagine that instead of points I was talking about pixels. I’m asking for an algorithm that takes a curve (n control points, m degrees) and tries to match the pixels. Drawing a line through each pixel, and then trying to simplify the line, seems backwards to me.

What I am looking for is a lot closer to OCR in concept, and there are certainly machine learning approaches that can take data (the points), an input vector (curve control point positions), and return a new set of control points so that the curve approximates the points. What is needed is some objective function (quantifying the fit), and some logic behind tweaking the controls points. My question was whether anyone had come up with something like that.

Another way of looking at this: any competent designer can draw a curve in rhino, and within a minute come up with a set of control points that will get the curve very close to the points. I suppose you could argue this is more of an AI problem, than ML, but the distinction is fuzzy…

Tom

And just for fun, a quote:

“Machine Learning is just glorified ‘curve fitting’ ” - Turing Prize winner Judea Pearl

https://towardsdatascience.com/watching-machine-learning-models-fitting-a-curve-c594fec4bbdb

NURBS curves are polynomial curves, I was not referring to using equations but to the mathematical support they have. There is some equivalence, there is non linear regression.

I don’t know what you mean by to match the pixels, but again it sounds like it can be solved more easily (maybe with rasterization or vectorization).

You asked how to fit a curve on those (very linear) points, but okay, I didn’t know.

Playing at reductionism… you can model everything as a regression problem, that doesn’t mean that everything is a regression problem.

Well, I would argue that if the time it’s going to take you by hand is less than modeling a generic solution (which may not exist, may depend on initial adjustments for example), you should do it by hand. But I understand that you asked just in case.

If it was for those particular points, I didn’t see the point of getting outside of analytical solutions, that was my point. If you need something you haven’t mentioned before like converting text or arbitrary point cloud based shapes to nurbs or something like that, which could (or not) requires ML to generalize the solution, then look for shape/text recognition or edge detection or whatever, for the area or task of ML, instead of assuming a solution, because from this you can find the tools out there with the right software, in addition, your input and output data are easily communicable. I can’t help more, and it’s difficult for others if you don’t specify the variability of your data or better detail the problem, instead of asking for a specific solution.

There are some papers out there about NURBS fitting, some using ML and others no.

Hi Dany,

The issue I am trying to address is slicing a real-world 3D scan of a boat hull. The data are messy, with scans overlapping, not always perfectly. The base surfaces, however, are quite smooth (or at least they should be!), so the slices can usually be represented by a simple NURBs curve.

In most cases, I can estimate the type of curve that should fit the shape (number of points and degree). Fitting the curves manually, however, is very time-consuming. Since all the “slices” can be presented by the same type of curve, I am hoping to come up with a solution that will automate some of this, which would be a very useful tool.

For context, here is the full curve I am trying to fit. The image in my first post is just one of the ends; I can see how it would look linear! 4,300 points and that is the low-resolution version of the scan!

Tom

Tom,

Mesh2Surface might be worth looking at … it seems like you want a reverse engineering solution.

Thanks for the pointer - I do indeed. I had checked Mesh2Surface a while ago, but will give it another try

I work with point clouds a good bit. Rhino 8 has a Shrinkwrap function that might be worth looking into and slicing the resulting surface. I tried R8 just for this reason but found it more “buggy” than R7 so haven’t fully explored this method.

Something else to remember is that whenever there are multiple, overlapping scans, there will be a certain amount of “registration error” (how tightly they align with each other) on top of the scanner’s own accuracy/tolerance. For this reason I generally have each scan on its own sublayer in Rhino to isolate the most relevant scan for that area. I tend to get truer results if the points I’m snapping to are from the same scan.

Let us know what ends up working best for your workflow. Maybe we’ll all learn something! Cheers.

1 Like