Esempio n. 1
0
        public void FirstDerivative()
        {
            IInterpolation ip = LinearSpline.Interpolate(_t, _y);

            Assert.That(ip.Differentiate(-3.0), Is.EqualTo(1.0));
            Assert.That(ip.Differentiate(-2.0), Is.EqualTo(1.0));
            Assert.That(ip.Differentiate(-1.5), Is.EqualTo(1.0));
            Assert.That(ip.Differentiate(-1.0), Is.EqualTo(-3.0));
            Assert.That(ip.Differentiate(-0.5), Is.EqualTo(-3.0));
            Assert.That(ip.Differentiate(0.0), Is.EqualTo(1.0));
            Assert.That(ip.Differentiate(0.5), Is.EqualTo(1.0));
            Assert.That(ip.Differentiate(1.0), Is.EqualTo(1.0));
            Assert.That(ip.Differentiate(2.0), Is.EqualTo(1.0));
            Assert.That(ip.Differentiate(3.0), Is.EqualTo(1.0));
        }
Esempio n. 2
0
        public DemoSample GetSample(long timeMs)
        {
            long oldTime = sample.t;

            sample.t = timeMs * 1000000;             // from millisecond to nanosecond

            double time = ((double)timeMs) / 1000.0; // from milliseconds to seconds

            if (time > TIME_MAX)                     // return zero speed and acceleration after 20 seconds run time
            {
                sample.s = sample.x = sample.y = sample.z = 0;
            }
            else
            {
                sample.s = (float)(spline.Interpolate(time) / 3.6); // 3.6 = from km/h to m/s

                float acceleration = (float)spline.Differentiate(time);
                sample.x = acceleration / 10;
                sample.y = acceleration / 10;
                sample.z = acceleration / 5;
            }

            // distance : integrate speed over time
            // distance += currentSpeed * (t1 - t0) // t1 = currentTime // t0 = oldTime
            float deltaTime = (float)(sample.t - oldTime) / 1000000000; // from nanoseconds to seconds

            sample.d += sample.s * deltaTime;

            return(sample);
        }
        /// <summary>
        /// Differentiates the specified point to get the steepest gradient.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <returns>UV.</returns>
        public UV Differentiate(UV point)
        {
            Index index = this._cellularFloor.FindIndex(point);

            if (this.Origins.Contains(this._cellularFloor.Cells[index.I, index.J]))
            {
                UV vector = this.DefaultState.Location - point;
                vector.Unitize();
                return(vector);
            }
            try
            {
                IInterpolation u_Interpolation = this.interpolation_U(point, index);
                IInterpolation v_Interpolation = this.interpolation_V(point, index);
                return(new UV(-1 * u_Interpolation.Differentiate(point.U),
                              -1 * v_Interpolation.Differentiate(point.V)));
            }
            catch (Exception)
            {
            }
            return(null);
        }