Exemplo n.º 1
0
        private void ReadMatrixMarketBanner(string line)
        {
            // line = MatrixMarket matrix coordinate real general

            string[] token = line.Split(seperator, StringSplitOptions.RemoveEmptyEntries);

            if (token.Length != 5)
            {
                throw new FormatException();
            }

            if (token[0] != "MatrixMarket")
            {
                throw new FormatException(); // Expected MatrixMarket format
            }

            if (token[1] != "matrix")
            {
                throw new FormatException(); // Expected matrix content
            }

            if (token[2] != "coordinate")
            {
                throw new FormatException(); // Expected matrix to be in coordinate format
            }

            // Type may be: real | complex | integer | pattern
            var type         = token[3].ToLowerInvariant();
            var expectedType = typeof(T);

            if (expectedType == typeof(double) && type != "real")
            {
                throw new FormatException(); // Expected matrix to have real entries
            }
            else if (expectedType == typeof(Complex) && type != "complex")
            {
                throw new FormatException(); // Expected matrix to have complex entries
            }

            string structure = token[4].ToLowerInvariant();

            if (structure == "symmetric")
            {
                this.matrixStructure = MatrixStructure.Symmetric;
            }
            else if (structure == "skew-symmetric")
            {
                this.matrixStructure = MatrixStructure.SkewSymmetric;
            }
            else if (structure == "hermitian")
            {
                this.matrixStructure = MatrixStructure.Hermitian;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MatrixMarketReader{T}"/> class.
        /// </summary>
        /// <param name="filename">Name of the file to read from.</param>
        public MatrixMarketReader(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentException(); // TODO: Resources.StringNullOrEmpty, "filename");
            }

            if (!File.Exists(filename))
            {
                throw new FileNotFoundException(); // TODO: Resources.FileDoesNotExist, "filename");
            }

            this.filename = filename;

            this.rowCount        = -1;
            this.offset          = 1;
            this.matrixStructure = MatrixStructure.General;
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Translate the matrix origin
        /// </summary>
        /// <param name="x">
        /// </param>
        /// <param name="y">
        /// </param>
        public void Translate(float x, float y)
        {
            var matrix = new MatrixStructure
            {
                P11 = 1,
                P12 = 0,
                P13 = 0,
                P21 = 0,
                P22 = 1,
                P23 = 0,
                P31 = x,
                P32 = y,
                P33 = 1
            };

            // Console.WriteLine("Translate\n" + matrix);

            MatrixMultiply(matrix);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Rotates matrix by using the given vectors
        /// </summary>
        public void Rotate(Vector2 heading, Vector2 side)
        {
            var matrix = new MatrixStructure
            {
                P11 = heading.X,
                P12 = heading.Y,
                P13 = 0,
                P21 = side.X,
                P22 = side.Y,
                P23 = 0,
                P31 = 0,
                P32 = 0,
                P33 = 1
            };

            // Console.WriteLine("Rotate\n" + matrix);

            MatrixMultiply(matrix);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Rotates matrix by given angle
        /// </summary>
        /// <param name="angle">
        /// </param>
        public void Rotate(float angle)
        {
            var sin = Math.Sin(angle);
            var cos = Math.Cos(angle);

            var matrix = new MatrixStructure
            {
                P11 = (float)cos,
                P12 = (float)sin,
                P13 = 0,
                P21 = (float)-sin,
                P22 = (float)cos,
                P23 = 0,
                P31 = 0,
                P32 = 0,
                P33 = 1
            };

            MatrixMultiply(matrix);
        }
Exemplo n.º 6
0
        private void MatrixMultiply(MatrixStructure matrix)
        {
            var tempMatrix = new MatrixStructure
            {
                // First row
                P11 = _matrix.P11 * matrix.P11 + _matrix.P12 * matrix.P21 + _matrix.P13 * matrix.P31,
                P12 = _matrix.P11 * matrix.P12 + _matrix.P12 * matrix.P22 + _matrix.P13 * matrix.P32,
                P13 = _matrix.P11 * matrix.P13 + _matrix.P12 * matrix.P23 + _matrix.P13 * matrix.P33,

                // Second row
                P21 = _matrix.P21 * matrix.P11 + _matrix.P22 * matrix.P21 + _matrix.P23 * matrix.P31,
                P22 = _matrix.P21 * matrix.P12 + _matrix.P22 * matrix.P22 + _matrix.P23 * matrix.P32,
                P23 = _matrix.P21 * matrix.P13 + _matrix.P22 * matrix.P23 + _matrix.P23 * matrix.P33,

                // Third row
                P31 = _matrix.P31 * matrix.P11 + _matrix.P32 * matrix.P21 + _matrix.P33 * matrix.P31,
                P32 = _matrix.P31 * matrix.P12 + _matrix.P32 * matrix.P22 + _matrix.P33 * matrix.P32,
                P33 = _matrix.P31 * matrix.P13 + _matrix.P32 * matrix.P23 + _matrix.P33 * matrix.P33
            };

            _matrix = tempMatrix;
        }