/// <summary>
        /// Transforms a <see cref="M3__x4t__"/> to a <see cref="M3__x3t__"/> by deleting the
        /// specified row and column. Internally the <see cref="M3__x4t__"/> is tarnsformed
        /// to a <see cref="M4__x4t__"/> to delete the row and column.
        /// </summary>
        /// <param name="deleted_row">Row to delete.</param>
        /// <param name="deleted_column">Column to delete.</param>
        /// <returns>A <see cref="M3__x3t__"/>.</returns>
        public M3__x3t__ Minor(int deleted_row, int deleted_column)
        {
            M4__x4t__ temp = (M4__x4t__)this;

            M3__x3t__ result      = new M3__x3t__();
            int       checked_row = 0;

            for (int actual_row = 0; actual_row < 4; actual_row++)
            {
                int checked_column = 0;

                if (actual_row != deleted_row)
                {
                    for (int actual_column = 0; actual_column < 4; actual_column++)
                    {
                        if (actual_column != deleted_column)
                        {
                            result[checked_row, checked_column] = temp[actual_row, actual_column];
                            checked_column++;
                        }
                    }
                    checked_row++;
                }
            }

            return(result);
        }
Exemple #2
0
        public Similarity__x3t__(M4__x4t__ m, __ft__ epsilon = (__ft__)0.00001)
        {
            if (!(m.M30.IsTiny(epsilon) && m.M31.IsTiny(epsilon) && m.M32.IsTiny(epsilon)))
            {
                throw new ArgumentException("Matrix contains perspective components.");
            }
            if (m.M33.IsTiny(epsilon))
            {
                throw new ArgumentException("Matrix is not homogeneous.");
            }
            m /= m.M33; //normalize it
            var m33 = (M3__x3t__)m;
            var s0  = m33.C0.Norm2;
            var s1  = m33.C1.Norm2;
            var s2  = m33.C2.Norm2;
            var s   = (s0 * s1 * s2).Pow((__ft__)1.0 / 3); //geometric mean of scale

            if (!((s0 / s - 1).IsTiny(epsilon) && (s1 / s - 1).IsTiny(epsilon) && (s2 / s - 1).IsTiny(epsilon)))
            {
                throw new ArgumentException("Matrix features non-uniform scaling");
            }
            m33  /= s;
            Scale = s;
            EuclideanTransformation = new Euclidean__x3t__(m33, m.C3.XYZ);
        }
 public static M4__x4t__ Subtract(M4__x4t__ a, M3__x4t__ b)
 {
     return(new M4__x4t__(
                a.M00 - b.M00, a.M01 - b.M01, a.M02 - b.M02, a.M03 - b.M03,
                a.M10 - b.M10, a.M11 - b.M11, a.M12 - b.M12, a.M13 - b.M13,
                a.M20 - b.M20, a.M21 - b.M21, a.M22 - b.M22, a.M23 - b.M23,
                a.M30, a.M31, a.M32, a.M33 - 1
                ));
 }
 public static M4__x4t__ Add(M3__x4t__ a, M4__x4t__ b)
 {
     return(new M4__x4t__(
                a.M00 + b.M00, a.M01 + b.M01, a.M02 + b.M02, a.M03 + b.M03,
                a.M10 + b.M10, a.M11 + b.M11, a.M12 + b.M12, a.M13 + b.M13,
                a.M20 + b.M20, a.M21 + b.M21, a.M22 + b.M22, a.M23 + b.M23,
                b.M30, b.M31, b.M32, 1 + b.M33
                ));
 }
Exemple #5
0
        /// <summary>
        /// Computes from a <see cref="V__x3t__"/> point (origin) and
        /// a <see cref="V__x3t__"/> normal the transformation matrix
        /// and its inverse.
        /// </summary>
        /// <param name="origin">The point which will become the new origin.</param>
        /// <param name="normal">The normal vector of the new ground plane.</param>
        /// <param name="local2global">A <see cref="M4__x4t__"/>The trafo from local to global system.</param>
        /// <param name="global2local">A <see cref="M4__x4t__"/>The trafofrom global to local system.</param>
        public static void NormalFrame(V__x3t__ origin, V__x3t__ normal,
                                       out M4__x4t__ local2global, out M4__x4t__ global2local
                                       )
        {
            V__x3t__ min;
            __ft__   x = Fun.Abs(normal.X);
            __ft__   y = Fun.Abs(normal.Y);
            __ft__   z = Fun.Abs(normal.Z);

            if (x < y)
            {
                if (x < z)
                {
                    min = V__x3t__.XAxis;
                }
                else
                {
                    min = V__x3t__.ZAxis;
                }
            }
            else
            {
                if (y < z)
                {
                    min = V__x3t__.YAxis;
                }
                else
                {
                    min = V__x3t__.ZAxis;
                }
            }

            V__x3t__ xVec = Vec.Cross(normal, min);

            xVec.Normalize(); // this is now guaranteed to be normal to the input normal
            V__x3t__ yVec = Vec.Cross(normal, xVec);

            yVec.Normalize();
            V__x3t__ zVec = normal;

            zVec.Normalize();

            local2global = new M4__x4t__(xVec.X, yVec.X, zVec.X, origin.X,
                                         xVec.Y, yVec.Y, zVec.Y, origin.Y,
                                         xVec.Z, yVec.Z, zVec.Z, origin.Z,
                                         0, 0, 0, 1);

            M4__x4t__ mat = new M4__x4t__(xVec.X, xVec.Y, xVec.Z, 0,
                                          yVec.X, yVec.Y, yVec.Z, 0,
                                          zVec.X, zVec.Y, zVec.Z, 0,
                                          0, 0, 0, 1);

            var shift = M4__x4t__.Translation(-origin);

            global2local = mat * shift;
        }
        public static M4__x4t__ Enlarge(M3__x3t__ m)
        {
            M4__x4t__ enlarged = new M4__x4t__(
                m.M00, m.M01, m.M02, 0,
                m.M10, m.M11, m.M12, 0,
                m.M20, m.M21, m.M22, 0,
                0, 0, 0, 1.0f);

            return(enlarged);
        }
Exemple #7
0
 /// <summary>
 /// Computes a Coordiante Frame Transformation (Basis) from current CS into
 /// the (X, Y, Z)-System at a given Origin.
 /// Note: you can use it, to transform from RH to LH and vice-versa, all depending
 /// how you will specifie your new basis-vectors.
 /// </summary>
 /// <param name="xVec">New X Vector</param>
 /// <param name="yVec">New Y Vector</param>
 /// <param name="zVec">New Z vector</param>
 /// <param name="oVec">New Origin.</param>
 /// <param name="viewTrafo"></param>
 /// <param name="viewTrafoInverse"></param>
 public static void CoordinateFrameTransform(V__x3t__ xVec, V__x3t__ yVec, V__x3t__ zVec, V__x3t__ oVec,
                                             out M4__x4t__ viewTrafo, out M4__x4t__ viewTrafoInverse)
 {
     oVec      = -oVec;
     viewTrafo = new M4__x4t__(
         xVec.X, xVec.Y, xVec.Z, xVec.X * oVec.X + xVec.Y * oVec.Y + xVec.Z * oVec.Z,
         yVec.X, yVec.Y, yVec.Z, yVec.X * oVec.X + yVec.Y * oVec.Y + yVec.Z * oVec.Z,
         zVec.X, zVec.Y, zVec.Z, zVec.X * oVec.X + zVec.Y * oVec.Y + zVec.Z * oVec.Z,
         0, 0, 0, 1
         );
     viewTrafoInverse = new M4__x4t__(
         xVec.X, yVec.X, zVec.X, -oVec.X,
         xVec.Y, yVec.Y, zVec.Y, -oVec.Y,
         xVec.Z, yVec.Z, zVec.Z, -oVec.Z,
         0, 0, 0, 1
         );
 }
Exemple #8
0
        /// <summary>
        ///  Provides perspective projection matrix in terms of the vertical field of view angle a and the aspect ratio r.
        /// </summary>
        public static M4__x4t__ PerspectiveProjectionTransformRH(__ft__ a, __ft__ r, __ft__ n, __ft__ f)
        {
            //F / r     0      0      0
            //  0       F      0      0
            //  0       0      A      B
            //  0       0      -1     0
            __ft__ F = 1 / Fun.Tan(a / 2);
            __ft__ A = f / (n - f);
            __ft__ B = f * n / (n - f);

            M4__x4t__ P = new M4__x4t__(
                F / r, 0, 0, 0,
                0, F, 0, 0,
                0, 0, A, B,
                0, 0, -1, 0);

            return(P);
        }
Exemple #9
0
        /// <summary>
        ///  Provides perspective projection matrix.
        ///  The parameters describe the dimensions of the view volume.
        /// </summary>
        public static M4__x4t__ PerspectiveProjectionTransformRH(V__x2t__ size, __ft__ n, __ft__ f)
        {
            __ft__ w = size.X;
            __ft__ h = size.Y;
            // Fx      0      0      0
            //  0      Fy     0      0
            //  0      0      A      B
            //  0      0      -1     0
            __ft__    Fx = 2 * n / w;
            __ft__    Fy = 2 * n / h;
            __ft__    A  = f / (n - f);
            __ft__    B  = n * f / (n - f);
            M4__x4t__ P  = new M4__x4t__(
                Fx, 0, 0, 0,
                0, Fy, 0, 0,
                0, 0, A, B,
                0, 0, -1, 0);

            return(P);
        }
Exemple #10
0
        /// <summary>
        /// Builds a customized, left-handed perspective Off-Center projection matrix.
        /// </summary>
        public static M4__x4t__ PerspectiveProjectionTransformLH(__ft__ l, __ft__ r, __ft__ t, __ft__ b, __ft__ n, __ft__ f)
        {
            //  Fx     0      0     0
            //  0      Fy     0     0
            //  Sx     Sy     A     1
            //  0      0      B     0
            __ft__ Fx = 2 * n / (r - l);
            __ft__ Fy = 2 * n / (t - b);
            __ft__ Sx = (l + r) / (l - r);
            __ft__ Sy = (t + b) / (b - t);
            __ft__ A  = f / (f - n);
            __ft__ B  = n * f / (n - f);

            M4__x4t__ P = new M4__x4t__(
                Fx, 0, 0, 0,
                0, Fy, 0, 0,
                Sx, Sy, A, 1,
                0, 0, B, 0);

            return(P);
        }
Exemple #11
0
        /// <summary>
        /// Builds a customized, right-handed perspective Off-Center projection matrix.
        /// </summary>
        public static M4__x4t__ PerspectiveProjectionTransformRH(__ft__ l, __ft__ r, __ft__ t, __ft__ b, __ft__ n, __ft__ f)
        {
            // Fx      0      Sx     0
            //  0      Fy     Sy     0
            //  0      0      A      B
            //  0      0      -1     0
            __ft__ Fx = 2 * n / (r - l);
            __ft__ Fy = 2 * n / (t - b);
            __ft__ Sx = (l + r) / (r - l);
            __ft__ Sy = (t + b) / (t - b);
            __ft__ A  = f / (n - f);
            __ft__ B  = n * f / (n - f);

            M4__x4t__ P = new M4__x4t__(
                Fx, 0, Sx, 0,
                0, Fy, Sy, 0,
                0, 0, A, B,
                0, 0, -1, 0);

            return(P);
        }
Exemple #12
0
        /// <summary>
        /// Multiplacation of a <see cref="Shift__x3t__"/> with a <see cref="M4__x4t__"/>.
        /// </summary>
        public static M4__x4t__ Multiply(Shift__x3t__ shift, M4__x4t__ m)
        {
            return(new M4__x4t__(
                       m.M00 + shift.X * m.M30,
                       m.M01 + shift.X * m.M31,
                       m.M02 + shift.X * m.M32,
                       m.M03 + shift.X * m.M33,

                       m.M10 + shift.Y * m.M30,
                       m.M11 + shift.Y * m.M31,
                       m.M12 + shift.Y * m.M32,
                       m.M13 + shift.Y * m.M33,

                       m.M20 + shift.Z * m.M30,
                       m.M21 + shift.Z * m.M31,
                       m.M22 + shift.Z * m.M32,
                       m.M23 + shift.Z * m.M33,

                       m.M30,
                       m.M31,
                       m.M32,
                       m.M33
                       ));
        }
Exemple #13
0
        /// <summary>
        /// Multiplacation of a <see cref="Scale__x3t__"/> with a <see cref="M4__x4t__"/>.
        /// </summary>
        public static M4__x4t__ Multiply(Scale__x3t__ scale, M4__x4t__ mat)
        {
            return(new M4__x4t__(
                       scale.X * mat.M00,
                       scale.X * mat.M01,
                       scale.X * mat.M02,
                       scale.X * mat.M03,

                       scale.Y * mat.M10,
                       scale.Y * mat.M11,
                       scale.Y * mat.M12,
                       scale.Y * mat.M13,

                       scale.Z * mat.M20,
                       scale.Z * mat.M21,
                       scale.Z * mat.M22,
                       scale.Z * mat.M23,

                       mat.M30,
                       mat.M31,
                       mat.M32,
                       mat.M33
                       ));
        }