System.Windows.Forms.MathHelper.Hermite C# (CSharp) Method

Hermite() public static method

public static Hermite ( float value1, float tangent1, float value2, float tangent2, float amount ) : float
value1 float
tangent1 float
value2 float
tangent2 float
amount float
return float
        public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
        {
            // originaly from https://github.com/mono/MonoGame/
            // All transformed to double not to lose precission
            // Otherwise, for high numbers of param:amount the result is NaN instead of Infinity
            double v1 = value1, v2 = value2, t1 = tangent1, t2 = tangent2, s = amount, result;
            double sCubed = s * s * s;
            double sSquared = s * s;

            if (amount == 0f)
                result = value1;
            else if (amount == 1f)
                result = value2;
            else
                result = (2 * v1 - 2 * v2 + t2 + t1) * sCubed +
                    (3 * v2 - 3 * v1 - 2 * t1 - t2) * sSquared +
                    t1 * s +
                    v1;
            return (float)result;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Interpolates between two values using a cubic equation.
        /// </summary>
        /// <param name="value1">Source value.</param>
        /// <param name="value2">Source value.</param>
        /// <param name="amount">Weighting value.</param>
        /// <returns>Interpolated value.</returns>
        public static float SmoothStep(float value1, float value2, float amount)
        {
            // originaly from https://github.com/mono/MonoGame/
            // It is expected that 0 < amount < 1
            // If amount < 0, return value1
            // If amount > 1, return value2
            float result = MathHelper.Clamp(amount * UnityEngine.Time.deltaTime, 0f, 1f);

            result = MathHelper.Hermite(value1, 0f, value2, 0f, result);

            return(result);
        }