Exemple #1
0
 /// <summary>
 /// Creates a Vector4 from a Vector with first 4 elements of provided vector or 0 if vector is smaller
 /// </summary>
 /// <param name="value">N dimensions base vector</param>
 public Vector4(Vector value)
     : this(0, 0, 0, 0)
 {
     if (value == null)
         return;
     for (int i = 0; i < 4; ++i)
     {
         this.v[i] = i < value.Dimension ? value[i] : 0;
     }
 }
Exemple #2
0
        private static void MathTest1()
        {
            Vector v;
            Matrix m1 = new Matrix(4, 4,
                1, 0, 0, 0,
                0, 1, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1);
            Matrix m2 = new Matrix(2, 4,
                1, 0, 2, 0,
                0, 1, 0, 2);

            Matrix m3 = new Matrix(3, 3,
                1, 1, 1,
                1, 0, 0,
                0, 0, 1);

            Matrix m4 = new Matrix(5, 5,
                0, 0, 1, 0, 0,
                1, 0, 0, 0, 0,
                0, 1, 0, 0, 0,
                0, 0, 0, 1, 0,
                0, 0, 0, 0, 1);

            Vector v1 = new Vector(1, 2, 3, 4);

            v = 3*v1/v1.Length;

            m3 = m3.Inverse;
            m4 = m4.Inverse;
        }
 /// <summary>
 /// Calculates the output of the State Space Model for a given time and input signal
 /// </summary>
 /// <param name="time">The time for which the output will be calculated.</param>
 /// <param name="signal">Signal vector used to calculate the output.</param>
 /// <returns>The output of the State Space Model</returns>
 public abstract Vector Output(double time, Vector signal);
Exemple #4
0
        public static void Main(string[] args)
        {
            SvHangTest();
            string variableType;
            bool isArray;
            int arrayLength;
            string variableName;
            string variableData;
            string data;
            Response rsp;

            Trigonometric precalculated;
            long start;
            long end;

            start = System.GC.GetTotalMemory(true);
            precalculated = new Trigonometric(0.01);
            end = System.GC.GetTotalMemory(true);
            Console.WriteLine("Size of precalculated trig with precision of {0}: {1}k = {2}M", precalculated.Precision, (end - start) / 1024, (end - start) / (1024 * 1024));

            start = System.GC.GetTotalMemory(true);
            precalculated = new Trigonometric(0.001);
            end = System.GC.GetTotalMemory(true);
            Console.WriteLine("Size of precalculated trig with precision of {0}: {1}k = {2}M", precalculated.Precision, (end - start) / 1024, (end - start) / (1024 * 1024));

            start = System.GC.GetTotalMemory(true);
            precalculated = new Trigonometric(0.0001);
            end = System.GC.GetTotalMemory(true);
            Console.WriteLine("Size of precalculated trig with precision of {0}: {1}k = {2}M", precalculated.Precision, (end - start) / 1024, (end - start) / (1024 * 1024));

            for (double d = -1.5708; d < 6; d += 0.0001)
                precalculated.Cos(d);

                start = System.GC.GetTotalMemory(true);
            precalculated = new Trigonometric(0.00001);
            end = System.GC.GetTotalMemory(true);
            Console.WriteLine("Size of precalculated trig with precision of {0}: {1}k = {2}M", precalculated.Precision, (end - start) / 1024, (end - start) / (1024 * 1024));

            start = System.GC.GetTotalMemory(true);
            precalculated = new Trigonometric(0.000001);
            end = System.GC.GetTotalMemory(true);
            Console.WriteLine("Size of precalculated trig with precision of {0}: {1}k = {2}M", precalculated.Precision, (end - start) / 1024, (end - start) / (1024 * 1024));

            start = System.GC.GetTotalMemory(true);
            precalculated = new Trigonometric(0.0000001);
            end = System.GC.GetTotalMemory(true);
            Console.WriteLine("Size of precalculated trig with precision of {0}: {1}k = {2}M", precalculated.Precision, (end - start) / 1024, (end - start) / (1024 * 1024));

            double result = precalculated.Sin(0.0001);

            Robotics.API.PrimitiveSharedVariables.SharedVariableBuilder.BuildClass(typeof(SuperType), "Z:\\SuperTypeSharedVar.cs");
            Robotics.API.PrimitiveSharedVariables.SharedVariableBuilder.BuildClass(typeof(SuperType[]), "Z:\\SuperTypeArraySharedVar.cs");
            return;

            data = "{ RecognizedSpeech recognizedSpeech { 2 \"robot no\" 0.92161322 \"robot hello\" 0.91587275 } }";
            data = "read_var \"{ string connected \\\"BLK OBJ-FNDT\\\" }\" 1";
            rsp = Response.Parse(data);
            data = rsp.Parameters;

            Parser.ParseSharedVariable(data, out variableType, out isArray, out arrayLength, out variableName, out variableData);
            Robotics.HAL.Sensors.RecognizedSpeech speech;
            Robotics.API.MiscSharedVariables.RecognizedSpeechSharedVariable.SDeserialize(
            "{ 2 \"robot no\" 0.92161322 \"robot hello\" 0.91587275", out speech);

            Vector2 v2 = null;
            Vector3 v3 = Vector3.UnitZ;
            foo(new Vector3(1, 2, 3));
            Vector v = new Vector(v2);
            SharedVars();

            //Console.Read();
            //BenchmarkCommand();
            //MainMath2();
            //MainTypes();
            //MainSignature();
            //MainTypes();
            //MainFill();
            //MathTest1();
            //Console.Read();
        }
Exemple #5
0
        /// <summary>
        /// Subtracts a vector from a vector
        /// </summary>
        /// <param name="value1">Source vector</param>
        /// <param name="value2">Source vector</param>
        /// <returns>Result of the subtraction</returns>
        public static Vector Substract(Vector value1, Vector value2)
        {
            if ((value1 == null) || (value2 == null))
                throw new ArgumentNullException();

            if ((value1 == null) || (value2 == null))
                throw new ArgumentNullException();

            if (value1.Dimension != value2.Dimension)
                throw new ArgumentException("Incompatible vectors");
            double[] result = new double[value1.Dimension];
            for (int i = 0; i < value1.Dimension; ++i)
                result[i] = value1[i] - value2[i];
            return new Vector(result);
        }
 /// <summary>
 /// Calculates the derivative of the State Space Model for a given time and input signal
 /// </summary>
 /// <param name="time">The time for which the derivative will be calculated.</param>
 /// <param name="signal">Signal vector used to calculate the derivative.</param>
 /// <returns>The derivative of the State Space Model</returns>
 public abstract Vector Derivative(double time, Vector signal);
Exemple #7
0
 /// <summary>
 /// Raises each component of a vector to the specified power
 /// </summary>
 /// <param name="baseVector">Source vector to be raised to a power</param>
 /// <param name="power">A double-precision floating-point number that specifies a power</param>
 /// <returns>A vector with each component raised to the power scalar</returns>
 public static Vector Pow(Vector baseVector, double power)
 {
     if (baseVector == null) return new Vector(new double[0]);
     double[] pv = new double[baseVector.Length];
     for (int i = 0; i < pv.Length; ++i)
     {
         pv[i] = Math.Pow(baseVector[i], power);
     }
     return new Vector(pv);
 }
Exemple #8
0
 /// <summary>
 /// Raises a scalar to the specified power by each component of a vector
 /// </summary>
 /// <param name="baseScalar">A double-precision floating-point number to be raised to a power</param>
 /// <param name="power">A vector that specifies an array of powers</param>
 /// <returns>A vector with each component equals to he base scalar raised to the power of each vector component</returns>
 public static Vector Pow(double baseScalar, Vector power)
 {
     if (power == null) return new Vector(new double[0]);
     double[] pv = new double[power.Length];
     for (int i = 0; i < pv.Length; ++i)
     {
         pv[i] = Math.Pow(baseScalar, power[i]);
     }
     return new Vector(pv);
 }
Exemple #9
0
        /// <summary>
        /// Multiplies a vector by a scalar value
        /// </summary>
        /// <param name="value">Source vector</param>
        /// <param name="scalar">Scalar value</param>
        /// <returns>Result of the multiplication</returns>
        public static Vector Multiply(Vector value, double scalar)
        {
            if (value == null)
                throw new ArgumentNullException();

            double[] result = new double[value.v.Length];
            for (int i = 0; i < result.Length; ++i)
                result[i] = value[i] * scalar;
            return new Vector(result);
        }
Exemple #10
0
        /// <summary>
        /// Returns a vector pointing in the opposite direction
        /// </summary>
        /// <param name="value">Source vector</param>
        /// <returns>Vector pointing in the opposite direction</returns>
        public static Vector Negate(Vector value)
        {
            if (value == null)
                throw new ArgumentNullException();

            double[] result = new double[value.Dimension];
            for (int i = 0; i < value.Dimension; ++i)
                result[i] = value[i] * -1;
            return new Vector(result);
        }
Exemple #11
0
        /// <summary>
        /// Calculates the Manhattan Distance between two vectors.
        /// The Manhattan distance between two vectors is the sum of the absolute differences of their coordinates.
        /// </summary>
        /// <param name="value1">Source vector</param>
        /// <param name="value2">Source vector</param>
        /// <returns>The Manhattan Distance between the vectors.</returns>
        public static double ManhattanDistance(Vector value1, Vector value2)
        {
            if ((value1 == null) || (value2 == null))
                throw new ArgumentNullException();
            if (value1.Dimension != value2.Dimension)
                throw new ArgumentException("Incompatible vectors");
            double distance = 0;

            for (int i = 0; i < value1.Dimension; ++i)
                distance += Math.Abs(value1[i] - value2[i]);
            return distance;
        }
Exemple #12
0
        /// <summary>
        /// Calculates the dot product of two vectors
        /// </summary>
        /// <param name="value1">Source vector</param>
        /// <param name="value2">Source vector</param>
        /// <returns>The dot product of the two vectors</returns>
        public static double Dot(Vector value1, Vector value2)
        {
            if ((value1 == null) || (value2 == null))
                throw new ArgumentNullException();

            if (value1.Dimension != value2.Dimension)
                throw new ArgumentException("Incompatible vectors");

            double result = 0;
            for (int i = 0; i < value1.Dimension; ++i)
                result += value1[i] * value2[i];
            return result;
        }
Exemple #13
0
        /// <summary>
        /// Calculates the Chebyshev Distance between two vectors.
        /// The Chebyshev distance between two vectors is the greatest of their differences along any coordinate dimension.
        /// </summary>
        /// <param name="value1">Source vector</param>
        /// <param name="value2">Source vector</param>
        /// <returns>The Chebyshev Distance between the vectors.</returns>
        public static double ChebyshevDistance(Vector value1, Vector value2)
        {
            if ((value1 == null) || (value2 == null))
                throw new ArgumentNullException();
            if (value1.Dimension != value2.Dimension)
                throw new ArgumentException("Incompatible vectors");
            double distance = 0;
            double d;

            for (int i = 0; i < value1.Dimension; ++i)
            {
                d = Math.Abs(value1[i] - value2[i]);
                if (d > distance)
                    distance = d;
            }
            return distance;
        }
Exemple #14
0
        /// <summary>
        /// Calculates the Canberra Distance between two vectors.
        /// The Canberra distance between two vectors is the sum of abs(pi - qi)/(abs(pi) + abs(qi))
        /// </summary>
        /// <param name="value1">Source vector</param>
        /// <param name="value2">Source vector</param>
        /// <returns>The Canberra Distance between the vectors.</returns>
        public static double CanberraDistance(Vector value1, Vector value2)
        {
            if ((value1 == null) || (value2 == null))
                throw new ArgumentNullException();
            if (value1.Dimension != value2.Dimension)
                throw new ArgumentException("Incompatible vectors");
            double distance = 0;
            double diff;
            double sum;

            for (int i = 0; i < value1.Dimension; ++i)
            {
                diff = Math.Abs(value1[i] - value2[i]);
                sum = Math.Abs(value1[i]) + Math.Abs(value2[i]);
                distance+= diff / sum;
            }
            return distance;
        }
Exemple #15
0
 /// <summary>
 /// Creates a Vector from another Vector
 /// This is a copy constructor
 /// </summary>
 /// <param name="value">Base vector</param>
 public Vector(Vector value)
 {
     if (value == null)
     {
         v = new double[0];
         return;
     }
     v = new double[value.Dimension];
     for (int i = 0; i < v.Length; ++i)
         v[i] = value[i];
 }