
Hi Roger, On Thu, Jan 20, 2022, at 07:13, roger.davies@geo-spatial.co.uk wrote:
I use a CAD package called Rhino which lets users write python scripts that run in the cad environment. I have a closed curve that is a design surface border and I have a sparse data set of 2D surveyed points taken around that border, so some error is included in the 2D data set. I would like to know what python function I could use to do a 2D best fit of the points to the curve.
This isn't exactly what you asked for, but in case you are looking to refine these points into a smoother, I've found subdivision splines very handy. To get the boundary conditions right is usually just a matter of repeating the start and end points enough times to cover the subdivision mask. Here is an example implementation of Catmul-Clark subdivision: https://github.com/matplotlib/viscm/blob/master/viscm/bezierbuilder.py#L323 You can choose subdivision coefficients so that the resulting curve goes exactly through your data points or not. Best regards, Stéfan