コード例 #1
0
        /*************************************************************************
        *  This function  calculates  tangent vector for a given value of parameter T
        *
        *  INPUT PARAMETERS:
        *   P   -   parametric spline interpolant
        *   T   -   point:
        * T in [0,1] corresponds to interval spanned by points
        * for non-periodic splines T<0 (or T>1) correspond to parts of
        *             the curve before the first (after the last) point
        * for periodic splines T<0 (or T>1) are projected  into  [0,1]
        *             by making T=T-floor(T).
        *
        *  OUTPUT PARAMETERS:
        *   X    -   X-component of tangent vector (normalized)
        *   Y    -   Y-component of tangent vector (normalized)
        *
        *  NOTE:
        *   X^2+Y^2 is either 1 (for non-zero tangent vector) or 0.
        *
        *
        *  -- ALGLIB PROJECT --
        *    Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2tangent(ref pspline2interpolant p,
                                           double t,
                                           ref double x,
                                           ref double y)
        {
            double v  = 0;
            double v0 = 0;
            double v1 = 0;

            if (p.periodic)
            {
                t = t - (int)Math.Floor(t);
            }
            pspline2diff(ref p, t, ref v0, ref x, ref v1, ref y);
            if ((double)(x) != (double)(0) | (double)(y) != (double)(0))
            {
                //
                // this code is a bit more complex than X^2+Y^2 to avoid
                // overflow for large values of X and Y.
                //
                v = apserv.safepythag2(x, y);
                x = x / v;
                y = y / v;
            }
        }
コード例 #2
0
        /*************************************************************************
        *  This function  calculates  arc length, i.e. length of  curve  between  t=a
        *  and t=b.
        *
        *  INPUT PARAMETERS:
        *   P   -   parametric spline interpolant
        *   A,B -   parameter values corresponding to arc ends:
        * B>A will result in positive length returned
        * B<A will result in negative length returned
        *
        *  RESULT:
        *   length of arc starting at T=A and ending at T=B.
        *
        *
        *  -- ALGLIB PROJECT --
        *    Copyright 30.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static double pspline2arclength(ref pspline2interpolant p,
                                               double a,
                                               double b)
        {
            double result = 0;

            autogk.autogkstate  state = new autogk.autogkstate();
            autogk.autogkreport rep   = new autogk.autogkreport();
            double sx   = 0;
            double dsx  = 0;
            double d2sx = 0;
            double sy   = 0;
            double dsy  = 0;
            double d2sy = 0;

            autogk.autogksmooth(a, b, ref state);
            while (autogk.autogkiteration(ref state))
            {
                spline1d.spline1ddiff(ref p.x, state.x, ref sx, ref dsx, ref d2sx);
                spline1d.spline1ddiff(ref p.y, state.x, ref sy, ref dsy, ref d2sy);
                state.f = apserv.safepythag2(dsx, dsy);
            }
            autogk.autogkresults(ref state, ref result, ref rep);
            System.Diagnostics.Debug.Assert(rep.terminationtype > 0, "PSpline2ArcLength: internal error!");
            return(result);
        }
コード例 #3
0
 /*************************************************************************
 *  This function  calculates  the value of the parametric spline for a  given
 *  value of parameter T
 *
 *  INPUT PARAMETERS:
 *   P   -   parametric spline interpolant
 *   T   -   point:
 * T in [0,1] corresponds to interval spanned by points
 * for non-periodic splines T<0 (or T>1) correspond to parts of
 *             the curve before the first (after the last) point
 * for periodic splines T<0 (or T>1) are projected  into  [0,1]
 *             by making T=T-floor(T).
 *
 *  OUTPUT PARAMETERS:
 *   X   -   X-position
 *   Y   -   Y-position
 *
 *
 *  -- ALGLIB PROJECT --
 *    Copyright 28.05.2010 by Bochkanov Sergey
 *************************************************************************/
 public static void pspline2calc(ref pspline2interpolant p,
                                 double t,
                                 ref double x,
                                 ref double y)
 {
     if (p.periodic)
     {
         t = t - (int)Math.Floor(t);
     }
     x = spline1d.spline1dcalc(ref p.x, t);
     y = spline1d.spline1dcalc(ref p.y, t);
 }
コード例 #4
0
 /*************************************************************************
 *  This function calculates first and second derivative with respect to T.
 *
 *  INPUT PARAMETERS:
 *   P   -   parametric spline interpolant
 *   T   -   point:
 * T in [0,1] corresponds to interval spanned by points
 * for non-periodic splines T<0 (or T>1) correspond to parts of
 *             the curve before the first (after the last) point
 * for periodic splines T<0 (or T>1) are projected  into  [0,1]
 *             by making T=T-floor(T).
 *
 *  OUTPUT PARAMETERS:
 *   X   -   X-value
 *   DX  -   derivative
 *   D2X -   second derivative
 *   Y   -   Y-value
 *   DY  -   derivative
 *   D2Y -   second derivative
 *
 *
 *  -- ALGLIB PROJECT --
 *    Copyright 28.05.2010 by Bochkanov Sergey
 *************************************************************************/
 public static void pspline2diff2(ref pspline2interpolant p,
                                  double t,
                                  ref double x,
                                  ref double dx,
                                  ref double d2x,
                                  ref double y,
                                  ref double dy,
                                  ref double d2y)
 {
     if (p.periodic)
     {
         t = t - (int)Math.Floor(t);
     }
     spline1d.spline1ddiff(ref p.x, t, ref x, ref dx, ref d2x);
     spline1d.spline1ddiff(ref p.y, t, ref y, ref dy, ref d2y);
 }
コード例 #5
0
        /*************************************************************************
        *  This function returns vector of parameter values correspoding to points.
        *
        *  I.e. for P created from (X[0],Y[0])...(X[N-1],Y[N-1]) and U=TValues(P)  we
        *  have
        *   (X[0],Y[0]) = PSpline2Calc(P,U[0]),
        *   (X[1],Y[1]) = PSpline2Calc(P,U[1]),
        *   (X[2],Y[2]) = PSpline2Calc(P,U[2]),
        *   ...
        *
        *  INPUT PARAMETERS:
        *   P   -   parametric spline interpolant
        *
        *  OUTPUT PARAMETERS:
        *   N   -   array size
        *   T   -   array[0..N-1]
        *
        *
        *  NOTES:
        * for non-periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]=1
        * for periodic splines     U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]<1
        *
        *  -- ALGLIB PROJECT --
        *    Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2parametervalues(ref pspline2interpolant p,
                                                   ref int n,
                                                   ref double[] t)
        {
            int i_ = 0;

            System.Diagnostics.Debug.Assert(p.n >= 2, "PSpline2ParameterValues: internal error!");
            n = p.n;
            t = new double[n];
            for (i_ = 0; i_ <= n - 1; i_++)
            {
                t[i_] = p.p[i_];
            }
            t[0] = 0;
            if (!p.periodic)
            {
                t[n - 1] = 1;
            }
        }
コード例 #6
0
        /*************************************************************************
        *  This  function  builds  periodic  2-dimensional  parametric  spline  which
        *  starts at (X[0],Y[0]), goes through all points to (X[N-1],Y[N-1]) and then
        *  back to (X[0],Y[0]).
        *
        *  INPUT PARAMETERS:
        *   XY  -   points, array[0..N-1,0..1].
        *           XY[I,0:1] corresponds to the Ith point.
        *           XY[N-1,0:1] must be different from XY[0,0:1].
        *           Order of points is important!
        *   N   -   points count, N>=3 for other types of splines.
        *   ST  -   spline type:
        * 1     Catmull-Rom spline (Tension=0) with cyclic boundary conditions
        * 2     cubic spline with cyclic boundary conditions
        *   PT  -   parameterization type:
        * 0     uniform
        * 1     chord length
        * 2     centripetal
        *
        *  OUTPUT PARAMETERS:
        *   P   -   parametric spline interpolant
        *
        *
        *  NOTES:
        * this function  assumes  that there all consequent points  are  distinct.
        *  I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2),  (x2,y2)<>(x3,y3)  and  so  on.
        *  However, non-consequent points may coincide, i.e. we can  have  (x0,y0)=
        *  =(x2,y2).
        * last point of sequence is NOT equal to the first  point.  You  shouldn't
        *  make curve "explicitly periodic" by making them equal.
        *
        *  -- ALGLIB PROJECT --
        *    Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2buildperiodic(double[,] xy,
                                                 int n,
                                                 int st,
                                                 int pt,
                                                 ref pspline2interpolant p)
        {
            double[,] xyp = new double[0, 0];
            double[] tmp = new double[0];
            double   v   = 0;
            int      i   = 0;
            int      i_  = 0;

            xy = (double[, ])xy.Clone();

            System.Diagnostics.Debug.Assert(st >= 1 & st <= 2, "PSpline2BuildPeriodic: incorrect spline type!");
            System.Diagnostics.Debug.Assert(pt >= 0 & pt <= 2, "PSpline2BuildPeriodic: incorrect parameterization type!");
            System.Diagnostics.Debug.Assert(n >= 3, "PSpline2BuildPeriodic: N<3!");

            //
            // Prepare
            //
            p.n        = n;
            p.periodic = true;
            tmp        = new double[n + 1];
            xyp        = new double[n + 1, 2];
            for (i_ = 0; i_ <= n - 1; i_++)
            {
                xyp[i_, 0] = xy[i_, 0];
            }
            for (i_ = 0; i_ <= n - 1; i_++)
            {
                xyp[i_, 1] = xy[i_, 1];
            }
            for (i_ = 0; i_ <= 1; i_++)
            {
                xyp[n, i_] = xy[0, i_];
            }

            //
            // Build parameterization, check that all parameters are distinct
            //
            pspline2par(ref xyp, n + 1, pt, ref p.p);
            System.Diagnostics.Debug.Assert(apserv.apservaredistinct(p.p, n + 1), "PSpline2BuildPeriodic: consequent (or first and last) points are too close!");

            //
            // Build splines
            //
            if (st == 1)
            {
                for (i_ = 0; i_ <= n; i_++)
                {
                    tmp[i_] = xyp[i_, 0];
                }
                spline1d.spline1dbuildcatmullrom(p.p, tmp, n + 1, -1, 0.0, ref p.x);
                for (i_ = 0; i_ <= n; i_++)
                {
                    tmp[i_] = xyp[i_, 1];
                }
                spline1d.spline1dbuildcatmullrom(p.p, tmp, n + 1, -1, 0.0, ref p.y);
            }
            if (st == 2)
            {
                for (i_ = 0; i_ <= n; i_++)
                {
                    tmp[i_] = xyp[i_, 0];
                }
                spline1d.spline1dbuildcubic(p.p, tmp, n + 1, -1, 0.0, -1, 0.0, ref p.x);
                for (i_ = 0; i_ <= n; i_++)
                {
                    tmp[i_] = xyp[i_, 1];
                }
                spline1d.spline1dbuildcubic(p.p, tmp, n + 1, -1, 0.0, -1, 0.0, ref p.y);
            }
        }
コード例 #7
0
ファイル: interpolation.cs プロジェクト: KBrus/nton-rbm
        /*************************************************************************
        This function  calculates  arc length, i.e. length of  curve  between  t=a
        and t=b.

        INPUT PARAMETERS:
            P   -   parametric spline interpolant
            A,B -   parameter values corresponding to arc ends:
                    * B>A will result in positive length returned
                    * B<A will result in negative length returned

        RESULT:
            length of arc starting at T=A and ending at T=B.


          -- ALGLIB PROJECT --
             Copyright 30.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static double pspline2arclength(pspline2interpolant p,
            double a,
            double b)
        {
            double result = 0;
            autogk.autogkstate state = new autogk.autogkstate();
            autogk.autogkreport rep = new autogk.autogkreport();
            double sx = 0;
            double dsx = 0;
            double d2sx = 0;
            double sy = 0;
            double dsy = 0;
            double d2sy = 0;

            autogk.autogksmooth(a, b, state);
            while( autogk.autogkiteration(state) )
            {
                spline1d.spline1ddiff(p.x, state.x, ref sx, ref dsx, ref d2sx);
                spline1d.spline1ddiff(p.y, state.x, ref sy, ref dsy, ref d2sy);
                state.f = apserv.safepythag2(dsx, dsy);
            }
            autogk.autogkresults(state, ref result, rep);
            alglib.ap.assert(rep.terminationtype>0, "PSpline2ArcLength: internal error!");
            return result;
        }
コード例 #8
0
        /*************************************************************************
        This function calculates derivative, i.e. it returns (dX/dT,dY/dT).

        INPUT PARAMETERS:
            P   -   parametric spline interpolant
            T   -   point:
                    * T in [0,1] corresponds to interval spanned by points
                    * for non-periodic splines T<0 (or T>1) correspond to parts of
                      the curve before the first (after the last) point
                    * for periodic splines T<0 (or T>1) are projected  into  [0,1]
                      by making T=T-floor(T).

        OUTPUT PARAMETERS:
            X   -   X-value
            DX  -   X-derivative
            Y   -   Y-value
            DY  -   Y-derivative


          -- ALGLIB PROJECT --
             Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2diff(ref pspline2interpolant p,
            double t,
            ref double x,
            ref double dx,
            ref double y,
            ref double dy)
        {
            double d2s = 0;

            if( p.periodic )
            {
                t = t-(int)Math.Floor(t);
            }
            spline1d.spline1ddiff(ref p.x, t, ref x, ref dx, ref d2s);
            spline1d.spline1ddiff(ref p.y, t, ref y, ref dy, ref d2s);
        }
コード例 #9
0
ファイル: interpolation.cs プロジェクト: KBrus/nton-rbm
        /*************************************************************************
        This function  calculates  tangent vector for a given value of parameter T

        INPUT PARAMETERS:
            P   -   parametric spline interpolant
            T   -   point:
                    * T in [0,1] corresponds to interval spanned by points
                    * for non-periodic splines T<0 (or T>1) correspond to parts of
                      the curve before the first (after the last) point
                    * for periodic splines T<0 (or T>1) are projected  into  [0,1]
                      by making T=T-floor(T).

        OUTPUT PARAMETERS:
            X    -   X-component of tangent vector (normalized)
            Y    -   Y-component of tangent vector (normalized)
            
        NOTE:
            X^2+Y^2 is either 1 (for non-zero tangent vector) or 0.


          -- ALGLIB PROJECT --
             Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2tangent(pspline2interpolant p,
            double t,
            ref double x,
            ref double y)
        {
            double v = 0;
            double v0 = 0;
            double v1 = 0;

            x = 0;
            y = 0;

            if( p.periodic )
            {
                t = t-(int)Math.Floor(t);
            }
            pspline2diff(p, t, ref v0, ref x, ref v1, ref y);
            if( (double)(x)!=(double)(0) || (double)(y)!=(double)(0) )
            {
                
                //
                // this code is a bit more complex than X^2+Y^2 to avoid
                // overflow for large values of X and Y.
                //
                v = apserv.safepythag2(x, y);
                x = x/v;
                y = y/v;
            }
        }
コード例 #10
0
ファイル: interpolation.cs プロジェクト: KBrus/nton-rbm
        /*************************************************************************
        This function  calculates  the value of the parametric spline for a  given
        value of parameter T

        INPUT PARAMETERS:
            P   -   parametric spline interpolant
            T   -   point:
                    * T in [0,1] corresponds to interval spanned by points
                    * for non-periodic splines T<0 (or T>1) correspond to parts of
                      the curve before the first (after the last) point
                    * for periodic splines T<0 (or T>1) are projected  into  [0,1]
                      by making T=T-floor(T).

        OUTPUT PARAMETERS:
            X   -   X-position
            Y   -   Y-position


          -- ALGLIB PROJECT --
             Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2calc(pspline2interpolant p,
            double t,
            ref double x,
            ref double y)
        {
            x = 0;
            y = 0;

            if( p.periodic )
            {
                t = t-(int)Math.Floor(t);
            }
            x = spline1d.spline1dcalc(p.x, t);
            y = spline1d.spline1dcalc(p.y, t);
        }
コード例 #11
0
ファイル: interpolation.cs プロジェクト: KBrus/nton-rbm
        /*************************************************************************
        This function returns vector of parameter values correspoding to points.

        I.e. for P created from (X[0],Y[0])...(X[N-1],Y[N-1]) and U=TValues(P)  we
        have
            (X[0],Y[0]) = PSpline2Calc(P,U[0]),
            (X[1],Y[1]) = PSpline2Calc(P,U[1]),
            (X[2],Y[2]) = PSpline2Calc(P,U[2]),
            ...

        INPUT PARAMETERS:
            P   -   parametric spline interpolant

        OUTPUT PARAMETERS:
            N   -   array size
            T   -   array[0..N-1]


        NOTES:
        * for non-periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]=1
        * for periodic splines     U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]<1

          -- ALGLIB PROJECT --
             Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2parametervalues(pspline2interpolant p,
            ref int n,
            ref double[] t)
        {
            int i_ = 0;

            n = 0;
            t = new double[0];

            alglib.ap.assert(p.n>=2, "PSpline2ParameterValues: internal error!");
            n = p.n;
            t = new double[n];
            for(i_=0; i_<=n-1;i_++)
            {
                t[i_] = p.p[i_];
            }
            t[0] = 0;
            if( !p.periodic )
            {
                t[n-1] = 1;
            }
        }
コード例 #12
0
ファイル: interpolation.cs プロジェクト: KBrus/nton-rbm
        /*************************************************************************
        This  function  builds  periodic  2-dimensional  parametric  spline  which
        starts at (X[0],Y[0]), goes through all points to (X[N-1],Y[N-1]) and then
        back to (X[0],Y[0]).

        INPUT PARAMETERS:
            XY  -   points, array[0..N-1,0..1].
                    XY[I,0:1] corresponds to the Ith point.
                    XY[N-1,0:1] must be different from XY[0,0:1].
                    Order of points is important!
            N   -   points count, N>=3 for other types of splines.
            ST  -   spline type:
                    * 1     Catmull-Rom spline (Tension=0) with cyclic boundary conditions
                    * 2     cubic spline with cyclic boundary conditions
            PT  -   parameterization type:
                    * 0     uniform
                    * 1     chord length
                    * 2     centripetal

        OUTPUT PARAMETERS:
            P   -   parametric spline interpolant


        NOTES:
        * this function  assumes  that there all consequent points  are  distinct.
          I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2),  (x2,y2)<>(x3,y3)  and  so  on.
          However, non-consequent points may coincide, i.e. we can  have  (x0,y0)=
          =(x2,y2).
        * last point of sequence is NOT equal to the first  point.  You  shouldn't
          make curve "explicitly periodic" by making them equal.

          -- ALGLIB PROJECT --
             Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2buildperiodic(double[,] xy,
            int n,
            int st,
            int pt,
            pspline2interpolant p)
        {
            double[,] xyp = new double[0,0];
            double[] tmp = new double[0];
            int i_ = 0;

            xy = (double[,])xy.Clone();

            alglib.ap.assert(st>=1 && st<=2, "PSpline2BuildPeriodic: incorrect spline type!");
            alglib.ap.assert(pt>=0 && pt<=2, "PSpline2BuildPeriodic: incorrect parameterization type!");
            alglib.ap.assert(n>=3, "PSpline2BuildPeriodic: N<3!");
            
            //
            // Prepare
            //
            p.n = n;
            p.periodic = true;
            tmp = new double[n+1];
            xyp = new double[n+1, 2];
            for(i_=0; i_<=n-1;i_++)
            {
                xyp[i_,0] = xy[i_,0];
            }
            for(i_=0; i_<=n-1;i_++)
            {
                xyp[i_,1] = xy[i_,1];
            }
            for(i_=0; i_<=1;i_++)
            {
                xyp[n,i_] = xy[0,i_];
            }
            
            //
            // Build parameterization, check that all parameters are distinct
            //
            pspline2par(xyp, n+1, pt, ref p.p);
            alglib.ap.assert(apserv.aredistinct(p.p, n+1), "PSpline2BuildPeriodic: consequent (or first and last) points are too close!");
            
            //
            // Build splines
            //
            if( st==1 )
            {
                for(i_=0; i_<=n;i_++)
                {
                    tmp[i_] = xyp[i_,0];
                }
                spline1d.spline1dbuildcatmullrom(p.p, tmp, n+1, -1, 0.0, p.x);
                for(i_=0; i_<=n;i_++)
                {
                    tmp[i_] = xyp[i_,1];
                }
                spline1d.spline1dbuildcatmullrom(p.p, tmp, n+1, -1, 0.0, p.y);
            }
            if( st==2 )
            {
                for(i_=0; i_<=n;i_++)
                {
                    tmp[i_] = xyp[i_,0];
                }
                spline1d.spline1dbuildcubic(p.p, tmp, n+1, -1, 0.0, -1, 0.0, p.x);
                for(i_=0; i_<=n;i_++)
                {
                    tmp[i_] = xyp[i_,1];
                }
                spline1d.spline1dbuildcubic(p.p, tmp, n+1, -1, 0.0, -1, 0.0, p.y);
            }
        }
コード例 #13
0
ファイル: interpolation.cs プロジェクト: KBrus/nton-rbm
        /*************************************************************************
        This function  builds  non-periodic 2-dimensional parametric spline  which
        starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]).

        INPUT PARAMETERS:
            XY  -   points, array[0..N-1,0..1].
                    XY[I,0:1] corresponds to the Ith point.
                    Order of points is important!
            N   -   points count, N>=5 for Akima splines, N>=2 for other types  of
                    splines.
            ST  -   spline type:
                    * 0     Akima spline
                    * 1     parabolically terminated Catmull-Rom spline (Tension=0)
                    * 2     parabolically terminated cubic spline
            PT  -   parameterization type:
                    * 0     uniform
                    * 1     chord length
                    * 2     centripetal

        OUTPUT PARAMETERS:
            P   -   parametric spline interpolant


        NOTES:
        * this function  assumes  that  there all consequent points  are distinct.
          I.e. (x0,y0)<>(x1,y1),  (x1,y1)<>(x2,y2),  (x2,y2)<>(x3,y3)  and  so on.
          However, non-consequent points may coincide, i.e. we can  have  (x0,y0)=
          =(x2,y2).

          -- ALGLIB PROJECT --
             Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2build(double[,] xy,
            int n,
            int st,
            int pt,
            pspline2interpolant p)
        {
            double[] tmp = new double[0];
            int i_ = 0;

            xy = (double[,])xy.Clone();

            alglib.ap.assert(st>=0 && st<=2, "PSpline2Build: incorrect spline type!");
            alglib.ap.assert(pt>=0 && pt<=2, "PSpline2Build: incorrect parameterization type!");
            if( st==0 )
            {
                alglib.ap.assert(n>=5, "PSpline2Build: N<5 (minimum value for Akima splines)!");
            }
            else
            {
                alglib.ap.assert(n>=2, "PSpline2Build: N<2!");
            }
            
            //
            // Prepare
            //
            p.n = n;
            p.periodic = false;
            tmp = new double[n];
            
            //
            // Build parameterization, check that all parameters are distinct
            //
            pspline2par(xy, n, pt, ref p.p);
            alglib.ap.assert(apserv.aredistinct(p.p, n), "PSpline2Build: consequent points are too close!");
            
            //
            // Build splines
            //
            if( st==0 )
            {
                for(i_=0; i_<=n-1;i_++)
                {
                    tmp[i_] = xy[i_,0];
                }
                spline1d.spline1dbuildakima(p.p, tmp, n, p.x);
                for(i_=0; i_<=n-1;i_++)
                {
                    tmp[i_] = xy[i_,1];
                }
                spline1d.spline1dbuildakima(p.p, tmp, n, p.y);
            }
            if( st==1 )
            {
                for(i_=0; i_<=n-1;i_++)
                {
                    tmp[i_] = xy[i_,0];
                }
                spline1d.spline1dbuildcatmullrom(p.p, tmp, n, 0, 0.0, p.x);
                for(i_=0; i_<=n-1;i_++)
                {
                    tmp[i_] = xy[i_,1];
                }
                spline1d.spline1dbuildcatmullrom(p.p, tmp, n, 0, 0.0, p.y);
            }
            if( st==2 )
            {
                for(i_=0; i_<=n-1;i_++)
                {
                    tmp[i_] = xy[i_,0];
                }
                spline1d.spline1dbuildcubic(p.p, tmp, n, 0, 0.0, 0, 0.0, p.x);
                for(i_=0; i_<=n-1;i_++)
                {
                    tmp[i_] = xy[i_,1];
                }
                spline1d.spline1dbuildcubic(p.p, tmp, n, 0, 0.0, 0, 0.0, p.y);
            }
        }
コード例 #14
0
ファイル: interpolation.cs プロジェクト: KBrus/nton-rbm
 public override alglib.apobject make_copy()
 {
     pspline2interpolant _result = new pspline2interpolant();
     _result.n = n;
     _result.periodic = periodic;
     _result.p = (double[])p.Clone();
     _result.x = (spline1d.spline1dinterpolant)x.make_copy();
     _result.y = (spline1d.spline1dinterpolant)y.make_copy();
     return _result;
 }
コード例 #15
0
ファイル: interpolation.cs プロジェクト: KBrus/nton-rbm
        /*************************************************************************
        This function calculates first and second derivative with respect to T.

        INPUT PARAMETERS:
            P   -   parametric spline interpolant
            T   -   point:
                    * T in [0,1] corresponds to interval spanned by points
                    * for non-periodic splines T<0 (or T>1) correspond to parts of
                      the curve before the first (after the last) point
                    * for periodic splines T<0 (or T>1) are projected  into  [0,1]
                      by making T=T-floor(T).

        OUTPUT PARAMETERS:
            X   -   X-value
            DX  -   derivative
            D2X -   second derivative
            Y   -   Y-value
            DY  -   derivative
            D2Y -   second derivative


          -- ALGLIB PROJECT --
             Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2diff2(pspline2interpolant p,
            double t,
            ref double x,
            ref double dx,
            ref double d2x,
            ref double y,
            ref double dy,
            ref double d2y)
        {
            x = 0;
            dx = 0;
            d2x = 0;
            y = 0;
            dy = 0;
            d2y = 0;

            if( p.periodic )
            {
                t = t-(int)Math.Floor(t);
            }
            spline1d.spline1ddiff(p.x, t, ref x, ref dx, ref d2x);
            spline1d.spline1ddiff(p.y, t, ref y, ref dy, ref d2y);
        }
コード例 #16
0
        /*************************************************************************
        *  This function  builds  non-periodic 2-dimensional parametric spline  which
        *  starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]).
        *
        *  INPUT PARAMETERS:
        *   XY  -   points, array[0..N-1,0..1].
        *           XY[I,0:1] corresponds to the Ith point.
        *           Order of points is important!
        *   N   -   points count, N>=5 for Akima splines, N>=2 for other types  of
        *           splines.
        *   ST  -   spline type:
        * 0     Akima spline
        * 1     parabolically terminated Catmull-Rom spline (Tension=0)
        * 2     parabolically terminated cubic spline
        *   PT  -   parameterization type:
        * 0     uniform
        * 1     chord length
        * 2     centripetal
        *
        *  OUTPUT PARAMETERS:
        *   P   -   parametric spline interpolant
        *
        *
        *  NOTES:
        * this function  assumes  that  there all consequent points  are distinct.
        *  I.e. (x0,y0)<>(x1,y1),  (x1,y1)<>(x2,y2),  (x2,y2)<>(x3,y3)  and  so on.
        *  However, non-consequent points may coincide, i.e. we can  have  (x0,y0)=
        *  =(x2,y2).
        *
        *  -- ALGLIB PROJECT --
        *    Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2build(double[,] xy,
                                         int n,
                                         int st,
                                         int pt,
                                         ref pspline2interpolant p)
        {
            double[] tmp = new double[0];
            double   v   = 0;
            int      i   = 0;
            int      i_  = 0;

            xy = (double[, ])xy.Clone();

            System.Diagnostics.Debug.Assert(st >= 0 & st <= 2, "PSpline2Build: incorrect spline type!");
            System.Diagnostics.Debug.Assert(pt >= 0 & pt <= 2, "PSpline2Build: incorrect parameterization type!");
            if (st == 0)
            {
                System.Diagnostics.Debug.Assert(n >= 5, "PSpline2Build: N<5 (minimum value for Akima splines)!");
            }
            else
            {
                System.Diagnostics.Debug.Assert(n >= 2, "PSpline2Build: N<2!");
            }

            //
            // Prepare
            //
            p.n        = n;
            p.periodic = false;
            tmp        = new double[n];

            //
            // Build parameterization, check that all parameters are distinct
            //
            pspline2par(ref xy, n, pt, ref p.p);
            System.Diagnostics.Debug.Assert(apserv.apservaredistinct(p.p, n), "PSpline2Build: consequent points are too close!");

            //
            // Build splines
            //
            if (st == 0)
            {
                for (i_ = 0; i_ <= n - 1; i_++)
                {
                    tmp[i_] = xy[i_, 0];
                }
                spline1d.spline1dbuildakima(p.p, tmp, n, ref p.x);
                for (i_ = 0; i_ <= n - 1; i_++)
                {
                    tmp[i_] = xy[i_, 1];
                }
                spline1d.spline1dbuildakima(p.p, tmp, n, ref p.y);
            }
            if (st == 1)
            {
                for (i_ = 0; i_ <= n - 1; i_++)
                {
                    tmp[i_] = xy[i_, 0];
                }
                spline1d.spline1dbuildcatmullrom(p.p, tmp, n, 0, 0.0, ref p.x);
                for (i_ = 0; i_ <= n - 1; i_++)
                {
                    tmp[i_] = xy[i_, 1];
                }
                spline1d.spline1dbuildcatmullrom(p.p, tmp, n, 0, 0.0, ref p.y);
            }
            if (st == 2)
            {
                for (i_ = 0; i_ <= n - 1; i_++)
                {
                    tmp[i_] = xy[i_, 0];
                }
                spline1d.spline1dbuildcubic(p.p, tmp, n, 0, 0.0, 0, 0.0, ref p.x);
                for (i_ = 0; i_ <= n - 1; i_++)
                {
                    tmp[i_] = xy[i_, 1];
                }
                spline1d.spline1dbuildcubic(p.p, tmp, n, 0, 0.0, 0, 0.0, ref p.y);
            }
        }
コード例 #17
0
        /*************************************************************************
        This function returns vector of parameter values correspoding to points.

        I.e. for P created from (X[0],Y[0])...(X[N-1],Y[N-1]) and U=TValues(P)  we
        have
            (X[0],Y[0]) = PSpline2Calc(P,U[0]),
            (X[1],Y[1]) = PSpline2Calc(P,U[1]),
            (X[2],Y[2]) = PSpline2Calc(P,U[2]),
            ...

        INPUT PARAMETERS:
            P   -   parametric spline interpolant

        OUTPUT PARAMETERS:
            N   -   array size
            T   -   array[0..N-1]


        NOTES:
        * for non-periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]=1
        * for periodic splines     U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]<1

          -- ALGLIB PROJECT --
             Copyright 28.05.2010 by Bochkanov Sergey
        *************************************************************************/
        public static void pspline2parametervalues(ref pspline2interpolant p,
            ref int n,
            ref double[] t)
        {
            int i_ = 0;

            System.Diagnostics.Debug.Assert(p.n>=2, "PSpline2ParameterValues: internal error!");
            n = p.n;
            t = new double[n];
            for(i_=0; i_<=n-1;i_++)
            {
                t[i_] = p.p[i_];
            }
            t[0] = 0;
            if( !p.periodic )
            {
                t[n-1] = 1;
            }
        }