Example #1
0
 public Mat2f(Mat2f m)
 {
     for (int i = 0; i < Size; i++)
     {
         cols[i] = new Vec2f(m.cols[i]);
     }
 }
Example #2
0
        public void Inverse()
        {
            //Generated with https://github.com/willnode/N-Matrix-Programmer

            var det = this[0, 0] * this[1, 1]
                      - this[0, 1] * this[1, 0];

            if (det == 0)
            {
                throw new Exception("Error: determinant is zero can't calculate inverse");
            }
            det = 1 / det;

            Mat2f r = new Mat2f();

            r[0, 0] = det * (this[1, 1]);
            r[0, 1] = det * -(this[0, 1]);
            r[1, 0] = det * -(this[1, 0]);
            r[1, 1] = det * (this[0, 0]);

            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    this[i, j] = r[i, j];
                }
            }
        }
Example #3
0
        public static Mat2f Identity()
        {
            Mat2f m = new Mat2f();

            m[0, 0] = 1;
            m[1, 1] = 1;
            return(m);
        }
Example #4
0
        public Mat3f(Mat2f m, Vec3f v)
        {
            for (int i = 0; i < Size - 1; i++)
            {
                cols[i] = new Vec3f(m[i]);
            }

            cols[Size - 1] = new Vec3f(v);
        }
Example #5
0
 public void Set(Mat2f m)
 {
     for (int i = 0; i < Size; i++)
     {
         for (int j = 0; j < Size; j++)
         {
             this[i, j] = m[i, j];
         }
     }
 }
Example #6
0
        public Mat4(Mat2 topLeft, Mat2 topRight, Mat2 bottomLeft, Mat2f bottomRight)
        {
            for (int i = 0; i < Size; i++)
            {
                cols[i] = new Vec4();
            }

            this[0, 0] = topLeft[0, 0]; this[0, 1] = topLeft[0, 1]; this[0, 2] = topRight[0, 0]; this[0, 3] = topRight[0, 1];
            this[1, 0] = topLeft[1, 0]; this[1, 1] = topLeft[1, 1]; this[1, 2] = topRight[1, 0]; this[1, 3] = topRight[1, 1];
            this[2, 0] = bottomLeft[0, 0]; this[2, 1] = bottomLeft[0, 1]; this[2, 2] = bottomRight[0, 0]; this[2, 3] = bottomRight[0, 1];
            this[3, 0] = bottomLeft[1, 0]; this[3, 1] = bottomLeft[1, 1]; this[3, 2] = bottomRight[1, 0]; this[3, 3] = bottomRight[1, 1];
        }
Example #7
0
        public static Mat2f operator *(Mat2f l, Mat2f r)
        {
            Mat2f Result = new Mat2f();

            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    for (int k = 0; k < Size; k++)
                    {
                        Result[i, j] += l[i, k] * r[k, j];
                    }
                }
            }
            return(Result);
        }