Exemplo n.º 1
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) == 0)
            {
                return;
            }
            Point p = new Point();

            p.X = e.X;
            p.Y = e.Y;
            list_V.Add(p);


            Gf            bestF = funcs[0];
            List <double> bestC = null;

            foreach (Gf func in funcs)
            {
                List <double> c = LSM.CalcLSM(func, list_V);
                bestC = c;
            }

            if (bestC == null)
            {
                return;
            }



            float r = 5;

            ImageGraphics.FillRectangle(mBackgroundBrush, 0, 0, 800, 800);
            foreach (Point point in list_V)
            {
                ImageGraphics.FillEllipse(mDotBrush, (float)point.X - r, (float)point.Y - r, 2 * r, 2 * r);
            }

            var n = p[0].;
Exemplo n.º 2
0
        public Function InterpolatePoints()
        {
            if (mPointList.Count < 5)
            {
                return(null);
            }
            List <Point> tp = new List <Point>();
            //get vect
            Vector directionVector = new Vector();

            directionVector.X = mPointList[mPointList.Count - 1].X - mPointList[0].X;
            directionVector.Y = mPointList[mPointList.Count - 1].Y - mPointList[0].Y;
            //normalize
            directionVector = directionVector.Normalize();
            //cslcu matrix
            Matrix m  = Matrix.mat(directionVector);
            Matrix mi = Matrix.Invert(m);

            //transform
            int n = mPointList.Count;

            for (int i = 0; i < n; i++)
            {
                tp.Add(mi.MulP(mPointList[i]));
            }

            List <double> bestC   = null;
            double        bestSqr = double.MaxValue;
            Gf            bestF   = funcs[0];

            foreach (Gf func in funcs)
            {
                List <double> c = LSM.CalcLSM(func, tp);
                if (c == null)
                {
                    continue;
                }
                double sqrs = 0;
                for (int j = 0; j < tp.Count; j++)
                {
                    sqrs += Math.Pow(tp[j].Y - func.CalcAll(c, tp[j].X), 2);
                }
                if (sqrs < bestSqr)
                {
                    bestSqr = sqrs;
                    bestF   = func;
                    bestC   = c;
                }
            }
            if (bestC == null)
            {
                return(null);
            }

            Function mFunction = new Function();

            mFunction.BestFunction             = bestF;
            mFunction.BestCoefficient          = bestC;
            mFunction.bestSqr                  = bestSqr;
            mFunction.Transform                = mi;
            mFunction.TransformInverse         = m;
            mFunction.TransformStartingPoint   = tp[0];
            mFunction.TransformStartingPoint.Y = mFunction.BestFunction.CalcAll(mFunction.BestCoefficient, mFunction.TransformStartingPoint.X);
            mFunction.TransformEndingPoint     = tp[mPointList.Count - 1];
            mFunction.TransformEndingPoint.Y   = mFunction.BestFunction.CalcAll(mFunction.BestCoefficient, mFunction.TransformEndingPoint.X);
            mFunction.StartingPoint            = mFunction.TransformInverse.MulP(mFunction.TransformStartingPoint);
            mFunction.EndingPoint              = mFunction.TransformInverse.MulP(mFunction.TransformEndingPoint);
            return(mFunction);
        }