Exemplo n.º 1
0
        public void CanInterpolateFact()
        {
            var interp = new LinearInterpolator();

            interp = new LinearInterpolator(new double[] { 0, 10 }, new double[] { 10, 10 });
            Assert.Equal(10.0, interp.Interpolate(100.0));
            var i2 = interp.Bump(1, 10, false);

            Assert.Equal(110.0, i2.Interpolate(100.0));
            interp.Bump(1, 10, true);
            Assert.Equal(110.0, interp.Interpolate(100.0));

            var interp2 = new LinearInterpolatorFlatExtrap();

            interp2 = new LinearInterpolatorFlatExtrap(new double[] { 0, 10 }, new double[] { 10, 10 });
            Assert.Equal(10.0, interp2.Interpolate(100.0));
            var i4 = interp2.Bump(1, 10, false);

            Assert.Equal(20, i4.Interpolate(100.0));
            interp2.Bump(1, 10, true);
            Assert.Equal(20, interp2.Interpolate(100.0));

            var interp3 = new LinearInterpolatorFlatExtrapNoBinSearch();

            interp3 = new LinearInterpolatorFlatExtrapNoBinSearch(new double[] { 0, 10 }, new double[] { 10, 10 });
            Assert.Equal(10.0, interp3.Interpolate(100.0));
            var i5 = interp3.Bump(1, 10, false);

            Assert.Equal(20, i5.Interpolate(100.0));
            interp3.Bump(1, 10, true);
            Assert.Equal(20, interp3.Interpolate(100.0));
        }
Exemplo n.º 2
0
        public void LinearInterpolatorTests_CanDifferentiate()
        {
            var interp = new LinearInterpolatorFlatExtrap(new double[] { 5, 10 }, new double[] { 5, 10 });

            Assert.Equal(0, interp.FirstDerivative(0));
            Assert.Equal(0, interp.FirstDerivative(20));
            Assert.Equal(1.0, interp.FirstDerivative(6));

            Assert.Equal(0, interp.SecondDerivative(0));
            Assert.Equal(0, interp.SecondDerivative(20));
            Assert.Equal(0.5, interp.SecondDerivative(5));

            var interp2 = new LinearInterpolator(new double[] { 5, 10 }, new double[] { 5, 10 });

            Assert.Equal(1.0, interp2.FirstDerivative(0));
            Assert.Equal(1.0, interp2.FirstDerivative(20));
            Assert.Equal(1.0, interp2.FirstDerivative(6));

            Assert.Equal(0.0, interp2.SecondDerivative(0));
            Assert.Equal(0.0, interp2.SecondDerivative(20));
            Assert.Equal(1.0, interp2.SecondDerivative(5));

            var interp3 = new LinearInterpolatorFlatExtrapNoBinSearch(new double[] { 5, 10 }, new double[] { 5, 10 });

            Assert.Equal(0, interp3.FirstDerivative(0));
            Assert.Equal(0, interp3.FirstDerivative(20));
            Assert.Equal(1.0, interp3.FirstDerivative(6), 6);

            Assert.Equal(0, interp3.SecondDerivative(0));
            Assert.Equal(0, interp3.SecondDerivative(20));
            Assert.Equal(0.0, interp3.SecondDerivative(5), 6);
        }
Exemplo n.º 3
0
        public void LinearInterpolatorTests_CanExtrapolate()
        {
            IInterpolator1D interp = new LinearInterpolator(new double[] { 5, 10 }, new double[] { 5, 10 });

            Assert.Equal(0, interp.Interpolate(0.0));
            Assert.Equal(7.5, interp.Interpolate(7.5));
            Assert.Equal(100, interp.Interpolate(100));
            Assert.Equal(1, interp.FirstDerivative(0));
            Assert.Equal(1, interp.FirstDerivative(5));
            Assert.Equal(1, interp.FirstDerivative(100));
            Assert.Equal(0, interp.SecondDerivative(0));
            Assert.Equal(1, interp.SecondDerivative(5));
            Assert.Equal(0, interp.SecondDerivative(100));

            interp = new LinearInterpolatorFlatExtrap(new double[] { 5, 10 }, new double[] { 5, 10 });
            Assert.Equal(5, interp.Interpolate(0.0));
            Assert.Equal(7.5, interp.Interpolate(7.5));
            Assert.Equal(10, interp.Interpolate(100));
            Assert.Equal(0, interp.FirstDerivative(0));
            Assert.Equal(1, interp.FirstDerivative(5));
            Assert.Equal(0, interp.FirstDerivative(100));
            Assert.Equal(0, interp.SecondDerivative(0));
            Assert.Equal(0.5, interp.SecondDerivative(5));
            Assert.Equal(0, interp.SecondDerivative(100));
        }
Exemplo n.º 4
0
        protected override void OnSizeChanged(int width, int height, int oldw, int oldh)
        {
            base.OnSizeChanged(width, height, oldw, oldh);

            Random        random       = new Random();
            IInterpolator interpolator = new LinearInterpolator();

            coords = new int[snow_flake_count][];
            drawables.Clear();
            for (int i = 0; i < snow_flake_count; i++)
            {
                //Console.WriteLine ("Add animation for number " + i);
                Animation animation = new TranslateAnimation(0, height / 10 - random.Next(height / 5), 0, height + 50);
                animation.Duration    = (10 * height + random.Next(10 * height)) + 3000;
                animation.RepeatCount = -1;
                animation.Initialize(10, 10, 10, 10);
                animation.Interpolator = interpolator;

                coords[i] = new int[] { random.Next(width - 30), -40 };
                //Console.WriteLine ("Coords = " + coords[i][0] + " and " + coords[i][1]);
                var snow = GetSnowFlake();
                snow.SetAlpha(random.Next(180, 255));
                drawables.Add(new AnimateDrawable(snow, animation));
                animation.StartOffset = random.Next(20 * height);
                animation.StartNow();
            }
        }
Exemplo n.º 5
0
        void SetInterpolator(int position)
        {
            IInterpolator CurrentInterpolator;

            switch (position)
            {
            case 1:
                CurrentInterpolator    = new LinearInterpolator();
                _seekBarFactor.Enabled = false;
                break;

            case 2:
                CurrentInterpolator    = new AccelerateDecelerateInterpolator();
                _seekBarFactor.Enabled = false;
                break;

            case 3:
                CurrentInterpolator    = new DecelerateInterpolator(_factor);
                _seekBarFactor.Enabled = true;
                break;

            case 0:
            default:
                CurrentInterpolator    = new AccelerateInterpolator(_factor);
                _seekBarFactor.Enabled = true;
                break;
            }

            _progressBar.SetSmoothProgressDrawableInterpolator(CurrentInterpolator);
            _progressBar.SetSmoothProgressDrawableColors(Resources.GetIntArray(Resource.Array.gplus_colors));
        }
Exemplo n.º 6
0
        private void SetValues()
        {
            _progressBar.SmoothProgressDrawableSpeed           = _speed;
            _progressBar.SmoothProgressDrawableSectionsCount   = _sectionsCount;
            _progressBar.SmoothProgressDrawableSeparatorLength = DpToPx(_separatorLength);
            _progressBar.SmoothProgressDrawableStrokeWidth     = DpToPx(_strokeWidth);
            _progressBar.SmoothProgressDrawableReversed        = _checkBoxReversed.Checked;
            _progressBar.SmoothProgressDrawableMirrorMode      = _checkBoxMirror.Checked;

            IInterpolator interpolator;

            switch (_spinnerInterpolators.SelectedItemPosition)
            {
            case 1:
                interpolator = new LinearInterpolator();
                break;

            case 2:
                interpolator = new AccelerateDecelerateInterpolator();
                break;

            case 3:
                interpolator = new DecelerateInterpolator();
                break;

            default:
                interpolator = new AccelerateInterpolator();
                break;
            }

            _progressBar.SmoothProgressDrawableInterpolator = interpolator;
            _progressBar.SmoothProgressDrawableColors       = IntsToColors(Resources.GetIntArray(Resource.Array.colors));
        }
Exemplo n.º 7
0
        public void AnimateMarker(double duration, LatLng startPosition, List <LatLng> wayPoints, int position)
        {
            if (wayPoints == null || !wayPoints.Any() || duration == 0)
            {
                return;
            }
            if (!isInit)
            {
                totalDuration = duration;
                totalDistance = CalculatorDistance(startPosition, wayPoints);
                isInit        = true;
            }
            Handler handler      = new Handler();
            long    start        = SystemClock.UptimeMillis();
            var     interpolator = new LinearInterpolator();
            var     nextLocation = wayPoints[position];
            var     nextDuration = MapHelpers.GetDistance(startPosition.Latitude, startPosition.Longitude,
                                                          nextLocation.Latitude, nextLocation.Longitude) * 1.0 / totalDistance * totalDuration;

            handler.Post(new MoveRunnable(_mMap, handler, interpolator, _mMarker, start, startPosition, nextLocation, nextDuration,
                                          () =>
            {
                position++;
                if (wayPoints.Count > position)
                {
                    AnimateMarker(duration, _mMarker.Position, wayPoints, position);
                }
                else
                {
                    _mMarker.Remove();
                }
            }));
        }
Exemplo n.º 8
0
        public IndicatorLayout(Context context, PullMode mode) : base(context)
        {
            mArrowImageView = new ImageView(context);

            Drawable arrowD = ContextCompat.GetDrawable(Context, Resource.Drawable.indicator_arrow); /*Resources.GetDrawable(Resource.Drawable.indicator_arrow);*/

            mArrowImageView.SetImageDrawable(arrowD);

            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int padding = getResources().getDimensionPixelSize(PullToRefresh.Resource.Dimension.indicator_internal_padding);
            int padding = Resources.GetDimensionPixelSize(Resource.Dimension.indicator_internal_padding);

            mArrowImageView.SetPadding(padding, padding, padding, padding);
            AddView(mArrowImageView);

            int inAnimResId, outAnimResId;

            switch (mode)
            {
            case PullMode.PULL_FROM_END:
                inAnimResId  = Resource.Animation.slide_in_from_bottom;
                outAnimResId = Resource.Animation.slide_out_to_bottom;
                SetBackgroundResource(Resource.Drawable.indicator_bg_bottom);

                // Rotate Arrow so it's pointing the correct way
                mArrowImageView.SetScaleType(ImageView.ScaleType.Matrix);
                Matrix matrix = new Matrix();
                matrix.SetRotate(180f, arrowD.IntrinsicWidth / 2f, arrowD.IntrinsicHeight / 2f);
                mArrowImageView.ImageMatrix = matrix;
                break;

            case PullMode.PULL_FROM_START:
            default:
                inAnimResId  = Resource.Animation.slide_in_from_top;
                outAnimResId = Resource.Animation.slide_out_to_top;
                SetBackgroundResource(Resource.Drawable.indicator_bg_top);
                break;
            }

            mInAnim = AnimationUtils.LoadAnimation(context, inAnimResId);
            mInAnim.SetAnimationListener(this);

            mOutAnim = AnimationUtils.LoadAnimation(context, outAnimResId);
            mOutAnim.SetAnimationListener(this);

            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final android.view.animation.Interpolator interpolator = new android.view.animation.LinearInterpolator();
            IInterpolator interpolator = new LinearInterpolator();

            mRotateAnimation = new RotateAnimation(0, -180, Dimension.RelativeToSelf, 0.5f, Dimension.RelativeToSelf, 0.5f);
            mRotateAnimation.Interpolator = interpolator;
            mRotateAnimation.Duration     = DEFAULT_ROTATION_ANIMATION_DURATION;
            mRotateAnimation.FillAfter    = true;

            mResetRotateAnimation = new RotateAnimation(-180, 0, Dimension.RelativeToSelf, 0.5f, Dimension.RelativeToSelf, 0.5f);
            mResetRotateAnimation.Interpolator = (interpolator);
            mResetRotateAnimation.Duration     = (DEFAULT_ROTATION_ANIMATION_DURATION);
            mResetRotateAnimation.FillAfter    = (true);
        }
Exemplo n.º 9
0
 public Path(string name) : base(name)
 {
     Rand = new Random(DateTime.Now.Millisecond + (1 + DateTime.Now.Second) * 1009 + (1 + DateTime.Now.Minute) * 62761 + (1 + DateTime.Now.Hour) * 3832999);
     ConnectedComponent = new List <Component>();
     Poly       = new LinearInterpolator();
     IsPassable = true;
     IsInfinity = true;
 }
 public ResizeAnimation(View view)
 {
     View         = view;
     Interpolator = new LinearInterpolator();
     startX       = Parameters.LeftMargin;
     startY       = Parameters.TopMargin;
     startW       = Parameters.Width;
     startH       = Parameters.Height;
 }
Exemplo n.º 11
0
            internal Bound(DoubleArray xValues, DoubleArray yValues) : base(xValues, yValues)
            {
                ArgChecker.isTrue(xValues.get(0) > 0d || xValues.get(xValues.size() - 1) < 0d, "xValues must have the same sign");
                this.xValues = xValues.toArrayUnsafe();
                this.yValues = yValues.toArrayUnsafe();
                LinearInterpolator underlying = new LinearInterpolator();

                this.poly     = underlying.interpolate(xValues.toArray(), getProduct(this.xValues, this.yValues));
                this.polySens = Suppliers.memoize(() => underlying.interpolateWithSensitivity(xValues.toArray(), getProduct(this.xValues, this.yValues)));
            }
        public static ContinuousCompoundingCurve GetFlatCurve(double rate)
        {
            var ratesByTenor = new SortedDictionary <double, double> {
                { 1, rate }
            };
            var interpolator = new LinearInterpolator();
            var curve        = new ContinuousCompoundingCurve(ratesByTenor, interpolator);

            return(curve);
        }
Exemplo n.º 13
0
 private void DrawPaths()
 {
     this.Controls.Where(i => i.Value.GetType() == typeof(Path)).ToList().ForEach((i) =>
     {
         LinearInterpolator pol = (i.Value as Path).Poly;
         for (int j = bounds.l; j < bounds.r; j++)
         {
             FillBuffer(j, ToInt32(pol.ValueForX(j) + Abs(pol.DerivativeForX(j))) + 2, Abs(ToInt32(pol.DerivativeForX(j)) * 2) + 4, 1, i.Value.MadeOf, i.Value.z);
         }
     });
 }
Exemplo n.º 14
0
 public MoveRunnable(GoogleMap gMap, Handler handler, LinearInterpolator interpolator, Marker m, long start, LatLng startPosition, LatLng toPosition, double duration, Action endAction)
 {
     _gMap          = gMap;
     _handler       = handler;
     _marker        = m;
     _interpolator  = interpolator;
     _start         = start;
     _startPosition = startPosition;
     _toPosition    = toPosition;
     _duration      = duration;
     _endAction     = endAction;
 }
Exemplo n.º 15
0
        public void play()
        {
            RotateAnimation    rotate = new RotateAnimation(0f, 360f, Dimension.RelativeToSelf, 0.5f, Dimension.RelativeToSelf, 0.5f);
            LinearInterpolator lin    = new LinearInterpolator();

            rotate.Interpolator = lin;
            rotate.Duration     = 2000;
            rotate.RepeatCount  = -1;
            rotate.FillAfter    = true;
            rotate.StartOffset  = 10;
            Animation           = rotate;
        }
        private AnnualCompoundingCurve GetCurve()
        {
            var ratesByTenor = new SortedDictionary <double, double>
            {
                { 0.5, 0.0025 },
                { 1, 0.005 },
                { 2, 0.005 },
                { 10, 0.025 }
            };

            var interpolator = new LinearInterpolator();
            var curve        = new AnnualCompoundingCurve(ratesByTenor, interpolator);

            return(curve);
        }
Exemplo n.º 17
0
        public void TestLinear2DInterpolationErrorForWrongNumberOfInputs()
        {
            // arrange
            var interpolator = new LinearInterpolator();
            var xVals        = new List <double> {
                -2, -2
            };
            var yVals = new List <double> {
                -3, -3, 4
            };
            var interpolate = -2;

            // act/assert
            var result = interpolator.Interpolate2D(xVals, yVals, interpolate);
        }
Exemplo n.º 18
0
        private static ContinuousCompoundingCurve GetCurve()
        {
            var ratesByTenor = new SortedDictionary <double, double>
            {
                { 0.5, 0.01 },
                { 1.0, 0.02 },
                { 2.0, 0.05 },
                { 5.0, 0.06 }
            };

            var interpolator = new LinearInterpolator();
            var curve        = new ContinuousCompoundingCurve(ratesByTenor, interpolator);

            return(curve);
        }
Exemplo n.º 19
0
        public void SensitivityFact()
        {
            var interp = new LinearInterpolator(new double[] { 0, 10 }, new double[] { 10, 10 });
            var r      = interp.Sensitivity(5);

            Assert.Equal(0.5, r[0]);
            Assert.Equal(0.5, r[1]);

            r = interp.Sensitivity(0);
            Assert.Equal(1.0, r[0]);
            Assert.Equal(0.0, r[1]);

            r = interp.Sensitivity(60);
            Assert.Equal(0.0, r[0]);
            Assert.Equal(1.0, r[1]);


            var interp2 = new LinearInterpolatorFlatExtrap(new double[] { 0, 10 }, new double[] { 10, 10 });
            var r2      = interp2.Sensitivity(5);

            Assert.Equal(0.5, r2[0]);
            Assert.Equal(0.5, r2[1]);

            r2 = interp2.Sensitivity(0);
            Assert.Equal(1.0, r2[0]);
            Assert.Equal(0.0, r2[1]);

            r2 = interp2.Sensitivity(60);
            Assert.Equal(0.0, r2[0]);
            Assert.Equal(1.0, r2[1]);


            var interp3 = new LinearInterpolatorFlatExtrapNoBinSearch(new double[] { 0, 10 }, new double[] { 10, 10 });
            var r3      = interp3.Sensitivity(5);

            Assert.Equal(0.5, r3[0]);
            Assert.Equal(0.5, r3[1]);

            r3 = interp3.Sensitivity(0);
            Assert.Equal(1.0, r3[0]);
            Assert.Equal(0.0, r3[1]);

            r3 = interp3.Sensitivity(60);
            Assert.Equal(0.0, r3[0]);
            Assert.Equal(1.0, r3[1]);
        }
Exemplo n.º 20
0
    public static void CapletVol20Y_InputInterp()
    {
        #region Data
        // We load a set of data (not real)
        DataForCapletExample1 d = new DataForCapletExample1();
        double[] df             = d.df();
        double[] yf             = d.yf();
        double[] T        = d.T();
        double[] fwd      = d.fwd();
        double[] atmfwd   = d.atmfwd();
        double[] capVol   = d.capVol();
        double[] avT      = d.avT();
        double[] avcapVol = d.avcapVol();
        #endregion

        // All Data available
        double[] CapletVol = Formula.CapletVolBootstrapping(T, df, fwd, yf, capVol, atmfwd);

        // Cubic input
        SimpleCubicInterpolator CubicInt = new SimpleCubicInterpolator(avT, avcapVol);
        double[] cubicInterpCapVol       = CubicInt.Curve(T);
        double[] CapletVolCubicInput     = Formula.CapletVolBootstrapping(T, df, fwd, yf, cubicInterpCapVol, atmfwd);

        // Linear Input
        LinearInterpolator LinearInt            = new LinearInterpolator(avT, avcapVol);
        double[]           linearInterpCapVol   = LinearInt.Curve(T);
        double[]           CapletVolLinearInput = Formula.CapletVolBootstrapping(T, df, fwd, yf, linearInterpCapVol, atmfwd);

        #region print results
        ExcelMechanisms exl                   = new ExcelMechanisms();
        Vector <double> CapletVol_            = new Vector <double>(CapletVol, 1);
        Vector <double> CapletVolCubicInput_  = new Vector <double>(CapletVolCubicInput, 1);
        Vector <double> CapletVolLinearInput_ = new Vector <double>(CapletVolLinearInput, 1);
        Vector <double> xarr                  = new Vector <double>(T, 1);
        List <string>   labels                = new List <string>()
        {
            "CapletVol All input", "CapVol Cubic Input", "CapVol Linear Input"
        };
        List <Vector <double> > yarrs = new List <Vector <double> >()
        {
            CapletVol_, CapletVolCubicInput_, CapletVolLinearInput_
        };

        exl.printInExcel <double>(xarr, labels, yarrs, "Caplet Vol Input Interpolation", "Term", "Volatility");
        #endregion
    }
Exemplo n.º 21
0
    public static void MatrixCaplet()
    {
        #region Data
        // We load a set of data (not real)
        DataForCapletExample2 d = new DataForCapletExample2();
        double[]        df      = d.df();
        double[]        yf      = d.yf();
        double[]        T       = d.T();
        double[]        avT     = d.avT();
        List <double[]> VolArr  = d.VolArr();
        double[]        fwd     = d.fwd();
        double[]        strike  = d.strike();

        List <double[]> VolSilos = new List <double[]>();
        foreach (double[] cVol in VolArr)
        {
            LinearInterpolator LinearInt = new LinearInterpolator(avT, cVol);
            VolSilos.Add(LinearInt.Curve(T));
        }

        #endregion
        // Here you can change the MonoStrikeCaplet Builder
        CapletMatrixVolBuilder <MonoStrikeCapletVolBuilderPWC> B = new CapletMatrixVolBuilder <MonoStrikeCapletVolBuilderPWC>(T, df, fwd, yf, avT, VolSilos, strike);

        // CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitSmooth> B = new CapletMatrixVolBuilder<MonoStrikeCapletVolBuilderBestFitSmooth>(T, df, fwd, yf, avT, VolSilos, strike);
        // and more...

        #region print results
        ExcelMechanisms exl    = new ExcelMechanisms();
        Vector <double> xarr   = new Vector <double>(T, 1);
        List <string>   labels = new List <string>();
        foreach (double myD in strike)
        {
            labels.Add(myD.ToString());
        }
        ;
        List <Vector <double> > yarrs = new List <Vector <double> >();
        foreach (double[] arr in B.CapletVolMatrix)
        {
            yarrs.Add(new Vector <double>(arr, 1));
        }

        exl.printInExcel <double>(xarr, labels, yarrs, "Caplet Vol Input Interpolation", "Term", "Volatility");
        #endregion
    }
Exemplo n.º 22
0
        public void TestLinearInterpolation2DNoInterpolation()
        {
            // arrange
            var interpolator = new LinearInterpolator();
            var xVals        = new List <double> {
                0, 5
            };
            var yVals = new List <double> {
                2, 7
            };
            var interpolate = 5;

            // act
            var result = interpolator.Interpolate2D(xVals, yVals, interpolate);

            // assert
            Assert.AreEqual(7, result);
        }
Exemplo n.º 23
0
        public void TestLinear2DInterpolationSamePoint()
        {
            // arrange
            var interpolator = new LinearInterpolator();
            var xVals        = new List <double> {
                -2, -2
            };
            var yVals = new List <double> {
                -3, -3
            };
            var interpolate = -2;

            // act
            var result = interpolator.Interpolate2D(xVals, yVals, interpolate);

            // assert
            Assert.AreEqual(-3, result);
        }
Exemplo n.º 24
0
        public void TestLinear2dInterpolationSmallToBig()
        {
            // arrange
            var interpolator = new LinearInterpolator();
            var xVals        = new List <double> {
                -2, 1.5
            };
            var yVals = new List <double> {
                3.2, 12.5
            };
            var interpolate = 0.5;

            // act
            var result = interpolator.Interpolate2D(xVals, yVals, interpolate);

            // assert
            Assert.AreEqual(9.842857, result, 1e-6);
        }
Exemplo n.º 25
0
        public void TestLinear2dInterpolationBigToSmall()
        {
            // arrange
            var interpolator = new LinearInterpolator();
            var xVals        = new List <double> {
                1, 2
            };
            var yVals = new List <double> {
                2.1, -0.8
            };
            var interpolate = 1.2;

            // act
            var result = interpolator.Interpolate2D(xVals, yVals, interpolate);

            // assert
            Assert.AreEqual(1.52, result, 1e-6);
        }
Exemplo n.º 26
0
        public void TestLinear3dInterpolationExceptionWrongNumberOfArguments()
        {
            // arrange
            var interpolator = new LinearInterpolator();
            var xVals        = new List <double> {
                1, 3.5, 1, 3.5, 10
            };
            var yVals = new List <double> {
                -0.8, -0.8, 1.2, 1.2
            };
            var zVals = new List <double> {
                1.2, 2.2, -3.4
            };
            var interpolate = new List <double> {
                2.1, 0.1
            };

            // act/assert
            var result = interpolator.Interpolate3D(xVals, yVals, zVals, interpolate);
        }
Exemplo n.º 27
0
        public Airfoil.Airfoil getAirfoil(int N)
        {
            //
            // Divide into upper and lower part
            //
            List <Point> upperList = new List <Point>();
            List <Point> lowerList = new List <Point>();
            var          le        = sourcePoints.min(PointExtensions.Axis.X);
            var          leIndex   = sourcePoints.find((Point)le);

            for (var i = leIndex; i >= 0; --i)
            {
                upperList.Add(sourcePoints[i]);
            }
            for (var i = leIndex; i < sourcePoints.Length; ++i)
            {
                lowerList.Add(sourcePoints[i]);
            }

            //
            // Interpolate upper and lower point to rearrage each points equidistantly.
            //
            var upperInterpolator = new LinearInterpolator(upperList.ToArray());
            var lowerInterpolator = new LinearInterpolator(lowerList.ToArray());

            var upperPoints = upperInterpolator.curveByConstantX(N);
            var lowerPoints = lowerInterpolator.curveByConstantX(N);
            var points      = new List <PairedPoint>();

            for (var i = 0; i < N; ++i)
            {
                points.Add(new PairedPoint(upperPoints[i].X, upperPoints[i].Y, lowerPoints[i].Y));
            }


            var airfoil = new Airfoil.Airfoil(points.ToArray());

            airfoil.name = csv?.valueName;

            return(airfoil);
        }
Exemplo n.º 28
0
        public void TestLinear3dInterpolation()
        {
            // arrange
            var interpolator = new LinearInterpolator();
            var xVals        = new List <double> {
                1, 3.5, 1, 3.5
            };
            var yVals = new List <double> {
                -0.8, -0.8, 1.2, 1.2
            };
            var zVals = new List <double> {
                1.2, 2.2, -3.4, 5
            };
            var interpolate = new List <double> {
                2.1, 0.1
            };

            // act
            var result = interpolator.Interpolate3D(xVals, yVals, zVals, interpolate);

            // assert
            Assert.AreEqual(1.0352, result, 1e-6);
        }
Exemplo n.º 29
0
        private void initView(Context context)
        {
            mContext        = context;
            updateUIHandler = new Handler((Message msg) =>
            {
                // 回弹速度随下拉距离moveDeltaY增大而增大
                moveSpeed = (float)(8 + 5 * Math.Tan(Math.PI / 2 / MeasuredHeight * (pullDownY + Math.Abs(pullUpY))));
                if (!isTouch)
                {
                    // 正在刷新,且没有往上推的话则悬停,显示"正在刷新..."
                    if (currentStatus == refreshing && pullDownY <= refreshDist)
                    {
                        pullDownY = refreshDist;
                        uScheduling.Cancel();
                    }
                    else if (currentStatus == loading && -pullUpY <= loadmoreDist)
                    {
                        pullUpY = -loadmoreDist;
                        uScheduling.Cancel();
                    }
                }
                if (pullDownY > 0)
                {
                    pullDownY -= moveSpeed;
                }
                else if (pullUpY < 0)
                {
                    pullUpY += moveSpeed;
                }
                if (pullDownY < 0)
                {
                    // 已完成回弹
                    pullDownY = 0;
                    pullView.ClearAnimation();
                    // 隐藏下拉头时有可能还在刷新,只有当前状态不是正在刷新时才改变状态
                    if (currentStatus != refreshing && currentStatus != loading)
                    {
                        changeStatus(initStatus);
                    }
                    uScheduling.Cancel();
                    RequestLayout();
                }
                if (pullUpY > 0)
                {
                    // 已完成回弹
                    pullUpY = 0;
                    pullUpView.ClearAnimation();
                    // 隐藏上拉头时有可能还在刷新,只有当前状态不是正在刷新时才改变状态
                    if (currentStatus != refreshing && currentStatus != loading)
                    {
                        changeStatus(initStatus);
                    }
                    uScheduling.Cancel();
                    RequestLayout();
                }
                // 刷新布局,会自动调用onLayout
                RequestLayout();
                // 没有拖拉或者回弹完成
                if (pullDownY + Math.Abs(pullUpY) == 0)
                {
                    uScheduling.Cancel();
                }
            });
            uScheduling     = new UIScheduling(updateUIHandler);
            rotateAnimation = (RotateAnimation)AnimationUtils.LoadAnimation(
                context, Resource.Animator.reverse_anim);
            refreshingAnimation = (RotateAnimation)AnimationUtils.LoadAnimation(
                context, Resource.Animator.rotating);
            // 添加匀速转动动画
            LinearInterpolator lir = new LinearInterpolator();

            rotateAnimation.Interpolator     = lir;
            refreshingAnimation.Interpolator = lir;
        }
Exemplo n.º 30
0
        private void AnimateTopLayer(float percent, bool force = false)
        {
            if (!canAnimate)
            {
                return;
            }

            if (height <= 0)
            {
                height = (float)topLayer.MeasuredHeight;
                if (height <= 0)
                {
                    return;
                }
            }

            canAnimate = false;

            var           start = animation == null ? -height : lastY;
            var           time  = 300;
            IInterpolator interpolator;


            if (percent < 0)
            {
                percent = 0;
            }
            else if (percent > 100)
            {
                percent = 100;
            }

            lastY = -height * (percent / 100F);

            if ((int)lastY == (int)start && !force)
            {
                canAnimate = true;
                return;
            }

            //is new so do bound, else linear
            if (fullAnimation || !Utils.IsSameDay)
            {
                interpolator  = new BounceInterpolator();
                time          = 3000;
                fullAnimation = false;
            }
            else
            {
                interpolator = new LinearInterpolator();
            }
            animation = new TranslateAnimation(Dimension.Absolute, 0,
                                               Dimension.Absolute, 0,
                                               Dimension.Absolute, start,
                                               Dimension.Absolute, lastY);
            animation.Duration = time;


            animation.Interpolator  = interpolator;
            animation.AnimationEnd += (object sender, Animation.AnimationEndEventArgs e) => {
                canAnimate = true;
            };

            animation.FillAfter = true;
            topLayer.StartAnimation(animation);
            if (topLayer.Visibility != Android.Views.ViewStates.Visible)
            {
                topLayer.Visibility = Android.Views.ViewStates.Visible;
            }
        }