コード例 #1
0
 public Mat3f(Mat3f m)
 {
     for (int i = 0; i < Size; i++)
     {
         cols[i] = new Vec3f(m.cols[i]);
     }
 }
コード例 #2
0
ファイル: Mat4.cs プロジェクト: abdalmoez/amathlib
        public Mat4(Mat3f m, Vec4 v)
        {
            for (int i = 0; i < Size - 1; i++)
            {
                cols[i] = new Vec4(m[i]);
            }

            cols[Size - 1] = new Vec4(v);
        }
コード例 #3
0
        public static Mat3f Identity()
        {
            Mat3f m = new Mat3f();

            m[0, 0] = 1;
            m[1, 1] = 1;
            m[2, 2] = 1;
            return(m);
        }
コード例 #4
0
 public void Set(Mat3f m)
 {
     for (int i = 0; i < Size; i++)
     {
         for (int j = 0; j < Size; j++)
         {
             this[i, j] = m[i, j];
         }
     }
 }
コード例 #5
0
        public static Mat3f operator *(Mat3f l, Mat3f r)
        {
            Mat3f Result = new Mat3f();

            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);
        }
コード例 #6
0
        public void Inverse()
        {
            //Generated with https://github.com/willnode/N-Matrix-Programmer

            var det =
                this[0, 0] * (this[1, 1] * this[2, 2] - this[1, 2] * this[2, 1])
                - this[0, 1] * (this[1, 0] * this[2, 2] - this[1, 2] * this[2, 0])
                + this[0, 2] * (this[1, 0] * this[2, 1] - this[1, 1] * this[2, 0]);


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

            Mat3f r = new Mat3f();

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

            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    this[i, j] = r[i, j];
                }
            }
        }