# Surface regression

Hi community!

Given a set of points, is it possible to get a surface that best fits the points? Similar to finding the best line or polynomial function that minimizes square error (in this case distances from the points to the square). Ideally, the simpler the better (to follow the analogy, it would be great to choose the degree of polynomial, rather than some degree=1000 that overfits to a ton of points)

I saw some CATIA videos where people select the mesh, then get a surface from the selected faces (though I think itās the points the faces are made of that mattered)

Thanks a lot!

1 Like

This seems like something people have researched (probably years ago) but, I think Iām missing the correct keywords in my searches

In 2D, my problem would look like this:

This image is from: Redirect Notice

Although I have to say I stopped working on it at some point. Also there was plugin called VSR which you canāt use anymore. It had a function to fit a surface to a mesh. From a practical standpoint you can only use such algorithm if it yields a proper curve/surface, and this has more to do with smoothing instead of fitting. Grasshopper is not the right tool for proper surface modelling. Almost any fundamental modelling tool is missing, meaning that fitting a surface is pointless if you cannot do more with it.

You find an okish algorithm in āThe Nurbs Bookā from Tiller and Piegl

1 Like

Thanks very much for your detailed reply Tom! I want to say that your project in the thread is a very important one! What Iām describing would be absolutely broken in the right situations

GH came to mind because of the coding part (also Rhinoās UI is way too hard for me). I was thinking more of points-in, surface-out algorithm so, I suppose thereās no surface modeling in the sense of adjusting the curves by hand. Certainly, having on access to important matrix tools like numpy, to say the least, has always been limiting.

Iām not sure if smoothing is the best way since it alters the input dataāI will elaborate in the following reply.

I will do some homework on the book (thanks for pointing me to that!) to see what I can find in the meantime

Consider a discretization of an NURBS surfaceāall vertices from a dense tri-remesh of an original. And letās say maybe 5% of the points are moved out of place at random.

With these points as input, I want to get the original NURBS back as much as possible. Thatās why some form of fitting came to mind

Constructing NURBS manually requires (sometimes many) curves so, thatās often plenty trial-and-error to minimize the visual discrepancy. Thatās not super awesomeālike doing āhard surfaceā modeling in Blender (Iām sure thereās a simpler analogy here )

This actually seems like a solved problem in some tools. But it would still be super good to have in GH!

not exactly a polynomial regression in 3d space, but if you have a mesh, you could pass it to a quadremesh and pass that to a subd

you might also like to play around with shrinkwrap in R8

if youāre starting from a list of points, you could pass those to a delunay triangulation ā quadremesh ->subd

otherwise, if youād like to get a single polynomial surface, you can use any modern tool that calculates that regression (mathematica comes to mind right now) and you can probably reconstruct a nurbs approximation

1 Like