Exemplo n.º 1
0
        public static Matrix_ ToMatrix(this Vector2 vec)
        {
            Matrix_ m = new Matrix_(new Vector2[, ] {
                { new Vector2(vec.X, 0) },
                { new Vector2(0, vec.Y) }
            });

            return(m);
        }
Exemplo n.º 2
0
        public static Matrix_ Multiply(Matrix_ a, Matrix_ b)
        {
            Matrix_ m = new Matrix_(new Vector2[, ] {
                { new Vector2((a.matrix[0, 0].X * b.matrix[0, 0].X) + (a.matrix[0, 0].Y * b.matrix[1, 0].X),
                              (a.matrix[0, 0].X * b.matrix[0, 0].Y) + (a.matrix[0, 0].Y * b.matrix[1, 0].Y)) },
                { new Vector2((a.matrix[1, 0].X * b.matrix[0, 0].X) + (a.matrix[1, 0].Y * b.matrix[1, 0].X),
                              (a.matrix[1, 0].X * b.matrix[0, 0].Y) + (a.matrix[1, 0].Y * b.matrix[1, 0].Y)) }
            });

            return(m);
        }
Exemplo n.º 3
0
        public static Matrix_ Scaler(Matrix_ a, float scaler)
        {
            for (int x = 0; x < a.matrix.GetLength(0); x++)
            {
                for (int y = 0; y < a.matrix.GetLength(1); y++)
                {
                    a.matrix[x, y] *= scaler;
                }
            }

            return(a);
        }
Exemplo n.º 4
0
        public Matrix_ Inverse()
        {
            //2x2
            float ad  = matrix[0, 0].X * matrix[1, 0].Y;
            float bc  = matrix[0, 0].Y * matrix[1, 0].X;
            float det = 1 / (ad - bc);

            //new matrix
            Matrix_ a = new Matrix_(new Vector2[, ] {
                { new Vector2(matrix[1, 0].Y, -matrix[0, 0].Y) },
                { new Vector2(-matrix[1, 0].X, matrix[0, 0].X) }
            });

            Matrix_ inverse = Scaler(a, det);

            return(inverse);
        }
Exemplo n.º 5
0
        public static Matrix_ Minus(Matrix_ a, Matrix_ b)
        {
            if (a.Order != b.Order)
            {
                return(null);
            }

            Matrix_ r = new Matrix_(a.order);

            for (int x = 0; x < a.matrix.GetLength(0); x++)
            {
                for (int y = 0; y < a.matrix.GetLength(1); y++)
                {
                    r.matrix[x, y] = a.matrix[x, y] - b.matrix[x, y];
                }
            }

            return(r);
        }
Exemplo n.º 6
0
        public static Matrix_ Translate(Matrix_ a, Matrix_ translation)
        {
            if (a.order != translation.order)
            {
                return(null);
            }

            Matrix_ r = new Matrix_(a.order);

            for (int x = 0; x < a.order.X; x++)
            {
                for (int y = 0; y < a.order.Y; y++)
                {
                    r.matrix[x, y] = new Vector2(a.matrix[x, y].X + translation.matrix[x, y].X,
                                                 a.matrix[x, y].Y + translation.matrix[x, y].Y);
                }
            }

            return(r);
        }