Exemplo n.º 1
0
        //----------------------------------------------------------------------------
        static public void eigentest()
        {
            double[,] m = new double[3, 3];
            m[0, 0]     = 2;
            m[0, 1]     = 1;
            m[0, 2]     = 1;
            m[1, 0]     = 1;
            m[1, 1]     = 2;
            m[1, 2]     = 1;
            m[2, 0]     = 1;
            m[2, 1]     = 1;
            m[2, 2]     = 2;
            Eigen e = new Eigen(m);

            e.EigenStuff();
            for (int i = 0; i <= 2; i++)
            {
                Vectors v = e.GetEigenvector(i);
                Debug.WriteLine("" + i + ", eigenvalue=" + e.GetEigenvalue(i) + ";");
                Debug.WriteLine("Eigenvector(" + v._X + "," + v._Y + "," + v._Z + ")");
            }
        }
Exemplo n.º 2
0
        //------------------------------------------------------------------------------
        public void analyseVectors(List <Vectors> p, int number)
        {
            // calculate  point count, centroid and
            // then plane by pca
            // p[0-2][] are coordinates
            // p[3][] if present, is weight
            int n = 0; //point count
            int i = 0;

            // means
            _m.set(0.0, 0.0, 0.0, 1.0d);
            double Ptx = 0.0d, Pty = 0.0d, Ptz = 0.0d;

            while (i < number)
            {
                _m._W  = 1.0d;
                Ptx    = p[i]._X;
                Pty    = p[i]._Y;
                Ptz    = p[i]._Z;
                _m._X += Ptx;
                _m._Y += Pty;
                _m._Z += Ptz;
                n++;
                i++;
            }
            _m /= n;
            // covariance
            double x, y, z;
            double xx, yy, zz;

            xx = yy = zz = 0.0d;
            double xy, yz, xz;

            xy = yz = xz = 0.0d;
            i  = number - 1;
            while (i >= 0)
            {
                _m._W = 1.0;
                Ptx   = p[i]._X;
                Pty   = p[i]._Y;
                Ptz   = p[i]._Z;
                x     = Ptx - _m._X; //p[0][i] - _m._X;
                y     = Pty - _m._Y; //p[1][i] - _m._Y;
                z     = Ptz - _m._Z; //p[2][i] - _m._Z;
                xx   += x * x;
                yy   += y * y;
                zz   += z * z;
                xy   += x * y;
                yz   += y * z;
                xz   += x * z;
                i--;
            }
            // standardize
            xx /= (double)n;
            yy /= (double)n;
            zz /= (double)n;
            xy /= (double)n;
            yz /= (double)n;
            xz /= (double)n;
            // setup matrix
            double[,] cov = new double[3, 3];
            cov[0, 0]     = xx;
            cov[0, 1]     = xy;
            cov[0, 2]     = xz;
            cov[1, 0]     = xy;
            cov[1, 1]     = yy;
            cov[1, 2]     = yz;
            cov[2, 0]     = xz;
            cov[2, 1]     = yz;
            cov[2, 2]     = zz;
            // do pca, smallest eigenvector is normal
            _e = new Eigen(cov);
            _e.EigenStuff();
            _normal   = _e.GetEigenvector(0);
            _eigenval = _e.GetEigenvalue(0);
            _dcent    = _normal._X * _m._X + _normal._Y * _m._Y + _normal._Z * _m._Z;
        }// analyse _pts
Exemplo n.º 3
0
        }// analyse _pts

        //------------------------------------------------------------------------------
        public void analyse(double[][] p, int number)
        {
            // calculate  point count, centroid and
            // then plane by pca
            // p[0-2][] are coordinates
            // p[3][] if present, is weight
            int n = 0; //point count
            int i = number - 1;

            // means
            _m.set(0.0, 0.0, 0.0, 0.0);
            while (i >= 0)
            {
                _m._W = 1.0d;
                if (p.GetLength(0) == 4)
                {
                    _m._W = p[3][i];
                }
                _m._X += p[0][i] * _m._W;
                _m._Y += p[1][i] * _m._W;
                _m._Z += p[2][i] * _m._W;
                n     += (int)_m._W;
                i--;
            }
            _m /= n;
            // covariance
            double x, y, z;
            double xx, yy, zz;

            xx = yy = zz = 0.0d;
            double xy, yz, xz;

            xy = yz = xz = 0.0d;
            i  = number - 1;
            while (i >= 0)
            {
                _m._W = 1.0;
                if (p.GetLength(0) == 4)
                {
                    _m._W = p[3][i];
                }
                x   = p[0][i] - _m._X;
                y   = p[1][i] - _m._Y;
                z   = p[2][i] - _m._Z;
                xx += _m._W * x * x;
                yy += _m._W * y * y;
                zz += _m._W * z * z;
                xy += _m._W * x * y;
                yz += _m._W * y * z;
                xz += _m._W * x * z;
                i--;
            }
            // standardize
            xx /= n;
            yy /= n;
            zz /= n;
            xy /= n;
            yz /= n;
            xz /= n;
            // setup matrix
            double[,] cov = new double[3, 3];
            cov[0, 0]     = xx;
            cov[0, 1]     = xy;
            cov[0, 2]     = xz;
            cov[1, 0]     = xy;
            cov[1, 1]     = yy;
            cov[1, 2]     = yz;
            cov[2, 0]     = xz;
            cov[2, 1]     = yz;
            cov[2, 2]     = zz;
            // do pca, smallest eigenvector is normal
            _e = new Eigen(cov);
            _e.EigenStuff();
            _normal   = _e.GetEigenvector(0);
            _eigenval = _e.GetEigenvalue(0);
            _dcent    = _normal._X * _m._X + _normal._Y * _m._Y + _normal._Z * _m._Z;
        }// analyse