Example #1
0
        public static MyMatrix FromVector2(Vector2 v)
        {
            MyMatrix ret = new MyMatrix(3, 1);

            double[,] arr = new double[3, 1]
            {
                { v.X },
                { v.Y },
                { 1.0 }
            };
            ret.SetValue(arr);
            return(ret);
        }
Example #2
0
        public static MyMatrix FromVector44(Vector4 v)
        {
            MyMatrix ret = new MyMatrix(5, 1);

            double[,] arr = new double[5, 1]
            {
                { v.X },
                { v.Y },
                { v.Z },
                { v.W },
                { 1.0 }
            };
            ret.SetValue(arr);
            return(ret);
        }
Example #3
0
        public static MyMatrix operator*(MyMatrix m1, MyMatrix m2)
        {
            if (m1.Cols != m2.Rows)
            {
                throw new ArgumentException("乘法:矩阵两边维度不匹配!");
            }
            MyMatrix ans = new MyMatrix(m1.Rows, m2.Cols);

            for (int i = 0; i < ans.Rows; i++)
            {
                for (int j = 0; j < ans.Cols; j++)
                {
                    for (int k = 0; k < m2.Rows; k++)
                    {
                        ans[i, j] += m1[i, k] * m2[k, j];
                    }
                }
            }
            return(ans);
        }