Exemplo n.º 1
0
 public void Transform(Matrix3 m)
 {
     var result = m.VectorMultiply(new double[4] {X, Y, Z, W});
     X = result[0];
     Y = result[1];
     Z = result[2];
     W = result[3];
 }
Exemplo n.º 2
0
        public static Matrix3 AzimuthElevation(double elevation, double azimuth, double oneOverd)
        {
            var result = new Matrix3();
            var rotate = new Matrix3();

            if (elevation > 90)
            {
                elevation = 90;
            }

            else if (elevation < -90)
            {
                elevation = -90;
            }

            if (azimuth > 180)
            {
                azimuth = 180;
            }

            else if (azimuth < -180)
            {
                azimuth = -180;
            }

            elevation = elevation*Math.PI/180.0;
            azimuth = azimuth*Math.PI/180.0;

            var sne = Math.Sin(elevation);
            var cne = Math.Cos(elevation);

            var sna = Math.Sin(azimuth);
            var cna = Math.Cos(azimuth);

            rotate.M[0, 0] = cna;
            rotate.M[0, 1] = sna;
            rotate.M[0, 2] = 0;

            rotate.M[1, 0] = -sne*sna;
            rotate.M[1, 1] = sne*cna;
            rotate.M[1, 2] = cne;

            rotate.M[2, 0] = cne*sna;
            rotate.M[2, 1] = -cne*cna;
            rotate.M[2, 2] = sne;

            if (oneOverd <= 0)
            {
                result = rotate;
            }

            else if (oneOverd > 0)
            {
                var perspective = Perspective(1/oneOverd);
                result = perspective*rotate;
            }

            return result;
        }
Exemplo n.º 3
0
        public static Matrix3 Euler(double alpha, double beta, double gamma)
        {
            var result = new Matrix3();

            alpha = alpha*Math.PI/180.0f;
            beta = beta*Math.PI/180.0f;
            gamma = gamma*Math.PI/180.0f;

            var sna = Math.Sin(alpha*Math.PI/180);
            var cna = Math.Cos(alpha*Math.PI/180);

            var snb = Math.Sin(beta*Math.PI/180);
            var cnb = Math.Cos(beta*Math.PI/180);

            var sng = Math.Sin(gamma*Math.PI/180);
            var cng = Math.Cos(gamma*Math.PI/180);

            result.M[0, 0] = cna*cng - sna*snb*sng;
            result.M[0, 1] = -snb*sng;
            result.M[0, 2] = sna*cng - cna*cnb*sng;

            result.M[1, 0] = -sna*snb;
            result.M[1, 1] = cnb;
            result.M[1, 2] = cna*cnb;

            result.M[2, 0] = -cna*sng - sna*cnb*cng;
            result.M[2, 1] = -snb*cng;
            result.M[2, 2] = cna*cnb*cng - sna*snb;

            return result;
        }
Exemplo n.º 4
0
        public static Matrix3 Perspective(double d)
        {
            var result = new Matrix3();

            result.M[3, 2] = -1/d;

            return result;
        }
Exemplo n.º 5
0
        public static Matrix3 Axonometric(double alpha, double beta)
        {
            var result = new Matrix3();

            var sna = Math.Sin(alpha*Math.PI/180);
            var cna = Math.Cos(alpha*Math.PI/180);

            var snb = Math.Sin(beta*Math.PI/180);
            var cnb = Math.Sin(beta*Math.PI/180);

            result.M[0, 0] = cnb;
            result.M[0, 2] = snb;
            result.M[1, 0] = sna*snb;
            result.M[1, 1] = cna;
            result.M[1, 2] = -sna*cnb;
            result.M[2, 2] = 0;

            return result;
        }
Exemplo n.º 6
0
        public static Matrix3 Oblique(double alpha, double theta)
        {
            var result = new Matrix3();

            var ta = Math.Tan(alpha*Math.PI/180);
            var snt = Math.Sin(theta*Math.PI/180);
            var cnt = Math.Cos(theta*Math.PI/180);

            result.M[0, 2] = -cnt/ta;
            result.M[1, 2] = -snt/ta;
            result.M[2, 2] = 0;

            return result;
        }
Exemplo n.º 7
0
        public static Matrix3 SideView()
        {
            var result = new Matrix3();

            result.M[0, 0] = 0;
            result.M[2, 2] = 0;
            result.M[0, 2] = -1;

            return result;
        }
Exemplo n.º 8
0
        public static Matrix3 TopView()
        {
            var result = new Matrix3();

            result.M[1, 1] = 0;
            result.M[2, 2] = 0;
            result.M[1, 2] = -1;

            return result;
        }
Exemplo n.º 9
0
        public static Matrix3 FrontView()
        {
            var result = new Matrix3();

            result.M[2, 2] = 0;

            return result;
        }
Exemplo n.º 10
0
        public static Matrix3 Rotate3Z(double theta)
        {
            theta = theta*Math.PI/180.0f;

            var sn = Math.Sin(theta);
            var cn = Math.Cos(theta);

            var result = new Matrix3();

            result.M[0, 0] = cn;
            result.M[0, 1] = -sn;
            result.M[1, 0] = sn;
            result.M[1, 1] = cn;

            return result;
        }
Exemplo n.º 11
0
        public static Matrix3 Translate3(double dx, double dy, double dz)
        {
            var result = new Matrix3();

            result.M[0, 3] = dx;
            result.M[1, 3] = dy;
            result.M[2, 3] = dz;

            return result;
        }
Exemplo n.º 12
0
        public static Matrix3 Scale3(double sx, double sy, double sz)
        {
            var result = new Matrix3();

            result.M[0, 0] = sx;
            result.M[1, 1] = sy;
            result.M[2, 2] = sz;

            return result;
        }
Exemplo n.º 13
0
        public static Matrix3 operator *(Matrix3 m1, Matrix3 m2)
        {
            var result = new Matrix3();

            for (var i = 0; i < 4; i++)
            {
                for (var j = 0; j < 4; j++)
                {
                    double element = 0;

                    for (var k = 0; k < 4; k++)
                    {
                        element += m1.M[i, k]*m2.M[k, j];
                    }

                    result.M[i, j] = element;
                }
            }

            return result;
        }