Ejemplo n.º 1
0
        /// <summary>
        /// Traverses a path of steepest ascent/descent until the desired potential is reached.
        /// </summary>
        /// <param name="pos">Starting point</param>
        /// <param name="desiredPotential">The field value you want to reach</param>
        /// <returns>The position the traversal ends at</returns>
        public static Vector3 GradientTraversal(this IScalarField field, Vector3 pos, double desiredPotential, double tolerance)
        {
            const double stepSize = 0.5; // TODO: tune this

            Vector3 currentPos    = pos;
            double  potentialDiff = desiredPotential - field.Value(currentPos);

            while (Math.Abs(potentialDiff) >= tolerance)
            {
                currentPos    = currentPos + (stepSize * potentialDiff) * field.Gradient(pos);
                potentialDiff = desiredPotential - field.Value(currentPos);
            }

            return(pos);
        }
Ejemplo n.º 2
0
        public void PotentialValueTest()
        {
            Vector3 point = new Vector3(5, 5, 5);

            double expectedPotentialValue = -(1.0 / point.Magnitude);

            Assert.That(expectedPotentialValue, Is.EqualTo(centralPotential.Value(point)));
        }