Example #1
0
        static public Matrix4d operator *(Matrix4d m1, Matrix4d m2)
        {
            Matrix4d mat = new Matrix4d();

            for (int i = 0; i < M; ++i)
            {
                for (int j = 0; j < N; ++j)
                {
                    for (int k = 0; k < N; ++k)
                    {
                        mat[i, j] += m1[i, k] * m2[k, j];
                    }
                }
            }
            return(mat);
        }
Example #2
0
        }// setMaxMinScaleFromMesh

        public void Transform(Matrix4d T)
        {
            _maxCoord = Vector3d.MinCoord;
            _minCoord = Vector3d.MaxCoord;
            for (int i = 0; i < _points3d.Length; ++i)
            {
                _points3d[i] = (T * new Vector4d(_points3d[i], 1)).ToVector3D();
                _maxCoord    = Vector3d.Max(_maxCoord, _points3d[i]);
                _minCoord    = Vector3d.Min(_minCoord, _points3d[i]);
            }
            foreach (Polygon3D p in _planes)
            {
                p.Transform(T);
            }
            _center = (_maxCoord + _minCoord) / 2;
            updateScale();
        }
Example #3
0
        public static Matrix4d RotationMatrix(Vector3d axis, double angle)
        {
            Matrix4d mat = new Matrix4d();

            double cos = Math.Cos(angle);
            double sin = Math.Sin(angle);

            axis.normalize();
            double x = axis[0], y = axis[1], z = axis[2];

            mat[0, 0] = cos + x * x * (1 - cos);
            mat[0, 1] = x * y * (1 - cos) - z * sin;
            mat[0, 2] = x * z * (1 - cos) + y * sin;
            mat[1, 0] = y * x * (1 - cos) + z * sin;
            mat[1, 1] = cos + y * y * (1 - cos);
            mat[1, 2] = y * z * (1 - cos) - x * sin;
            mat[2, 0] = z * x * (1 - cos) - y * sin;
            mat[2, 1] = z * y * (1 - cos) + x * sin;
            mat[2, 2] = cos + z * z * (1 - cos);
            mat[3, 3] = 1;

            return(mat);
        }
Example #4
0
        public static Matrix4d ReflectionalMatrix(Vector3d plane_normal)
        {
            // create an coordinates sys, with plane_normal as x-axis
            Vector3d x = plane_normal;
            Vector3d y;

            if (x.x == 0 && x.y == 0)
            {
                y = new Vector3d(1, 0, 0);
            }
            else
            {
                y = (new Vector3d(-x.y, x.x, 0)).normalize();
            }
            Vector3d z    = x.Cross(y).normalize();
            Matrix3d R    = new Matrix3d(x, y, z).Transpose();
            Matrix3d InvR = R.Inverse();
            Matrix4d U    = new Matrix4d(R);
            Matrix4d V    = new Matrix4d(InvR);
            Matrix4d I    = Matrix4d.IdentityMatrix();

            I[0, 0] = -1; // reflect matrix along yz plane
            return(V * I * U);
        }
Example #5
0
        }// getMinCoord

        public static Vector3d transformVector(Vector3d v, Matrix4d T)
        {
            return((T * new Vector4d(v, 1)).ToVector3D());
        }// transformVector
Example #6
0
 public void TransformOrigin(Matrix4d m)
 {
     _originPos3d = (m * new Vector4d(_originPos3d, 1)).ToVector3D();
 }
Example #7
0
 public void Transform(Matrix4d m)
 {
     _pos3d = (m * new Vector4d(_pos3d, 1)).ToVector3D();
 }
Example #8
0
        public static Vector3d GetMirrorSymmetryVector(Vector3d vec, Vector3d normal)
        {
            Matrix4d R = ReflectionalMatrix(normal);

            return((R * new Vector4d(vec, 0)).XYZ());
        }
Example #9
0
        public static Vector3d GetMirrorSymmetryPoint(Vector3d pt, Vector3d normal, Vector3d center)
        {
            Matrix4d R = ReflectionalMatrix(normal);

            return(center + (R * new Vector4d(pt - center, 0)).XYZ());
        }