private IInterpolation interpolation_U(UV point, Index index)
        {
            IndexRange horizontalExpansion = this.horizontalRange(index);

            //getting all vertical ranges of the horizontal
            IndexRange[] verticals = new IndexRange[horizontalExpansion.Length];
            Index        next      = horizontalExpansion.Min.Copy();

            for (int i = 0; i < horizontalExpansion.Length; i++)
            {
                verticals[i] = this.verticalRange(next);
                next.I++;
            }
            //getting interpolators for u values
            IInterpolation[] verticalsU = new IInterpolation[horizontalExpansion.Length];
            for (int i = 0; i < verticals.Length; i++)
            {
                verticalsU[i] = this.toInterpolation(verticals[i]);
            }
            //generating u interpolation
            double[] x = new double[horizontalExpansion.Length];
            double[] y = new double[horizontalExpansion.Length];
            next = horizontalExpansion.Min.Copy();
            for (int i = 0; i < horizontalExpansion.Length; i++)
            {
                x[i] = this._cellularFloor.FindCell(next).U;
                y[i] = verticalsU[i].Interpolate(point.V);
                next.I++;
            }
            IInterpolation interpolatorU = null;

            switch (Activity.InterpolationMethod)
            {
            case SpatialAnalysis.FieldUtility.InterpolationMethod.CubicSpline:
                if (x.Length > 1)
                {
                    interpolatorU = CubicSpline.InterpolateBoundariesSorted(x, y,
                                                                            SplineBoundaryCondition.Natural, 0,
                                                                            SplineBoundaryCondition.Natural, 0);
                }
                else
                {
                    interpolatorU = LinearSpline.InterpolateSorted(x, y);
                }
                break;

            //case FieldUtility.InterpolationMethod.Barycentric:
            //    interpolatorU = Barycentric.InterpolatePolynomialEquidistantSorted(x, y);
            //    break;
            case SpatialAnalysis.FieldUtility.InterpolationMethod.Linear:
                interpolatorU = LinearSpline.InterpolateSorted(x, y);
                break;

            default:
                break;
            }
            return(interpolatorU);
        }
        //http://numerics.mathdotnet.com/api/MathNet.Numerics.Interpolation/CubicSpline.htm
        /// <summary>
        /// Sets the interpolation formula.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        public void SetInterpolation(IEnumerable <double> x, IEnumerable <double> y)
        {
            this.GetCost = null;
            IInterpolation interpolation = CubicSpline.InterpolateBoundariesSorted(x.ToArray(), y.ToArray(),
                                                                                   SplineBoundaryCondition.Natural, 0, SplineBoundaryCondition.Natural, 0);

            this.GetCost             = new CalculateCost(interpolation.Interpolate);
            interpolation            = null;
            this.CostCalculationType = CostCalculationMethod.Interpolation;
        }
 private void updateFunc()
 {
     if (this._data.Count > 1)
     {
         this.interpolation = null;
         this.interpolation = CubicSpline.InterpolateBoundariesSorted(this._data.Keys.ToArray(), this._data.Values.ToArray(), SplineBoundaryCondition.Natural, 0, SplineBoundaryCondition.Natural, 0);
         this.updateGraph(20);
     }
     else
     {
         this.interpolation = null;
         this._graphs._graphsHost.Clear();
     }
 }
        private IInterpolation toInterpolation(IndexRange range)
        {
            double[] x    = new double[range.Length];
            double[] y    = new double[x.Length];
            Index    next = range.Min.Copy();

            switch (range.Direction)
            {
            case Direction.Horizontal:
                for (int i = 0; i < x.Length; i++)
                {
                    Cell cell = this._cellularFloor.FindCell(next);
                    x[i]    = cell.U;
                    y[i]    = this.Potentials[cell];
                    next.I += 1;
                }
                break;

            case Direction.Vertical:
                for (int i = 0; i < x.Length; i++)
                {
                    Cell cell = this._cellularFloor.FindCell(next);
                    x[i]    = cell.V;
                    y[i]    = this.Potentials[cell];
                    next.J += 1;
                }
                break;

            default:
                break;
            }
            IInterpolation interpolator = null;

            switch (Activity.InterpolationMethod)
            {
            case SpatialAnalysis.FieldUtility.InterpolationMethod.CubicSpline:
                if (x.Length > 1)
                {
                    interpolator = CubicSpline.InterpolateBoundariesSorted(x, y,
                                                                           SplineBoundaryCondition.Natural, 0,
                                                                           SplineBoundaryCondition.Natural, 0);
                }
                else
                {
                    interpolator = LinearSpline.InterpolateSorted(x, y);
                }
                break;

            //case FieldUtility.InterpolationMethod.Barycentric:
            //    interpolator = Barycentric.InterpolatePolynomialEquidistantSorted(x, y);
            //    break;
            case SpatialAnalysis.FieldUtility.InterpolationMethod.Linear:
                interpolator = LinearSpline.InterpolateSorted(x, y);
                break;

            default:
                break;
            }
            x    = null;
            y    = null;
            next = null;
            return(interpolator);
        }