# How to fit a fixed curve to measured points with minimum average deviation

What is the way to find the best possible fit of a drawn curve to measured data? The situation is as following: A certain curve is drawn, from which a series of pipes are bent. These pipes are then measured at certain points and read back into Rhino to compare it with the original curve. But in order to do this, the original curve has to be manually fit to the measured points, before there can be made a point deviation calculation.

Putting the ends on top of the end points for example could give 0 deviation at the ends, but too much in the middle of the curve, while it might be the case that by placing the curve differently the deviation at the ends can become somewhat larger, but keeps the deviation at other points lower and so lowering the overal average deviation.

In the attached you see an example of a curve and the measured points with a quick manual fit. Most likely not the optimum solution.
min_deviation.3dm (3.2 MB)

Hi Gijs - so the curve has to be maneuvered into place but not deformed in any way, is that correct?
If so, you might start with the end points lined up and then use `PointDeviation` and `Rotate3d` (on the end points) to dial it in a little closer, then take it from there, guided by the deviation feedback. `DragStrength` may also help in fine tuning.

-Pascal

Yes, correct, the curve is the reference to compare the measurement data to, so cannot be deformed.

Your idea was something I thought of, in that case it’s going to be a manual process. I was just wondering if there is a way to let the computer do some iterations and find the best result?

Hi Gijs - it seems at least possible that Grasshopper may have some tools that could help - via Galapagos, possibly…

Hmmm - find minimum bounding boxes for the curve and for the points and then align the bounding boxes…

-Pascal