public void substract(CXYVector v) { int n = _size; while ((n--) != 0) { this[n].substract(v[n]); } }
public void add(CXYVector v) { int n = _size; while ((n--) != 0) { this[n].add(v[n]); } }
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]; } }
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]); } }
public CXYVector multiplyCopy(double a) { CXYVector ret = new CXYVector(this); int n = _size; while ((n--) != 0) { ret[n].multiply(a); } return(ret); }
public CXYVector substractCopy(CVector2 v) { CXYVector ret = new CXYVector(this); int n = _size; while ((n--) != 0) { ret[n].substract(v); } return(ret); }
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); }
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); }
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); }