/// <summary> /// fit a curve to the specified points /// requires S parameter specified for each point /// requires at least 5 points /// </summary> /// <param name="points">points to fit to, minimum 5</param> internal static void SimpleFit(MouldCurve c, IFitPoint[] points) { Vect2 uv = new Vect2(); Vect3 x0 = new Vect3(); Vect3 x1 = new Vect3(); double[][] uFits = new double[2][]; double[] sFits = new double[points.Length]; uFits[0] = new double[points.Length]; uFits[1] = new double[points.Length]; //complile fitpoints to fitting arrays sFits[0] = 0; points[0][0] = 0; c.xVal(points[0].UV, ref x0);//initialize starting x point for (int nFit = 0; nFit < points.Length; nFit++) { //sFits[nFit] = fits[nFit][0]; uFits[0][nFit] = points[nFit][1]; uFits[1][nFit] = points[nFit][2]; if (nFit > 0) { c.xVal(points[nFit].UV, ref x1); points[nFit][0] = points[nFit - 1][0] + x1.Distance(x0); x0.Set(x1);//store previous x point } } for (int nFit = 0; nFit < points.Length; nFit++) sFits[nFit] = points[nFit][0] /= points.Last()[0];//convert length to position //sFits[sFits.Length-1] = fits.Last()[0] = 1;//enforce unit length c.FitPoints = points; c.ReSpline(sFits, uFits); }