예제 #1
0
        public void substract(CXYVector v)
        {
            int n = _size;

            while ((n--) != 0)
            {
                this[n].substract(v[n]);
            }
        }
예제 #2
0
        public void add(CXYVector v)
        {
            int n = _size;

            while ((n--) != 0)
            {
                this[n].add(v[n]);
            }
        }
예제 #3
0
 public CVector(CXYVector v)
 {
     _size = 2 * v.size;
     _v    = new double[_size];
     for (int i = 0; i < _size; i += 2)
     {
         _v[i]     = v[i / 2][0];
         _v[i + 1] = v[i / 2][1];
     }
 }
예제 #4
0
        public CXYVector(CXYVector v)
        {
            int i;

            _size = v.size;
            _v    = new CVector2[_size];
            for (i = 0; i < _size; i++)
            {
                _v[i] = new CVector2(v[i]);
            }
        }
예제 #5
0
        public CXYVector multiplyCopy(double a)
        {
            CXYVector ret = new CXYVector(this);
            int       n   = _size;

            while ((n--) != 0)
            {
                ret[n].multiply(a);
            }

            return(ret);
        }
예제 #6
0
        public CXYVector substractCopy(CVector2 v)
        {
            CXYVector ret = new CXYVector(this);
            int       n   = _size;

            while ((n--) != 0)
            {
                ret[n].substract(v);
            }

            return(ret);
        }
예제 #7
0
        public double distance(CXYVector target)
        {
            double res  = 0f;
            int    size = _size;

            while ((size--) != 0)
            {
                CVector2 temp = _v[size].substractCopy(target[size]);
                res += temp.length2();
            }

            return(res);
        }
예제 #8
0
        public double [] substractDouble(CXYVector v)
        {
            double [] ret = new double[_size * 2];
            int       i;

            for (i = 0; i < _size; i++)
            {
                ret[i * 2]     = _v[i][0] - v[i][0];
                ret[i * 2 + 1] = _v[i][1] - v[i][1];
            }

            return(ret);
        }
예제 #9
0
        public static CMatrix3x3 realign(CXYVector target, CXYVector anchor, double [] weight)
        {
            double X1, Y1, X2, Y2, W, Z, C1, C2;

            int k = anchor.size;

            X1 = Y1 = X2 = Y2 = W = Z = C1 = C2 = 0;

            while ((k--) != 0)
            {
                double x1 = anchor[k][0];
                double y1 = anchor[k][1];
                double x2 = target[k][0];
                double y2 = target[k][1];

                double w = weight[k];

                W += w;
                Z += w * (x2 * x2 + y2 * y2);

                X1 += w * x1; Y1 += w * y1;
                X2 += w * x2; Y2 += w * y2;
                C1 += w * (x1 * x2 + y1 * y2);
                C2 += w * (y1 * x2 - x1 * y2);
            }

            CVector4 solution =
                new CMatrix4x4(
                    new CVector4(X2, -Y2, W, 0),
                    new CVector4(Y2, X2, 0, W),
                    new CVector4(Z, 0, X2, Y2),
                    new CVector4(0, Z, -Y2, X2)
                    ).inverse().multiplyCopy(new CVector4(X1, Y1, C1, C2));

            CMatrix3x3 trx = new CMatrix3x3(
                new CVector3(solution[0], -solution[1], solution[2]),
                new CVector3(solution[1], solution[0], solution[3]),
                new CVector3(0, 0, 1));

            target.transform(trx);
            return(trx);
        }