public void matrixTransform( double a00, double a01, double a02, double a10, double a11, double a12, double a20, double a21, double a22) { ExpressionNode dummy = new ExpressionNode(); expression = expression.replaceAndWrap(fVars[0], dummy); double[][] b = MyMath.adjoint(a00, a01, a02, a10, a11, a12, a20, a21, a22); MyDouble[][] mbTrans = new MyDouble[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) mbTrans[i][j] = new MyDouble(kernel, b[j][i]); ExpressionNode newZ = new ExpressionNode(kernel, mbTrans[2][0], ExpressionNode.MULTIPLY, fVars[0]) .plus(new ExpressionNode(kernel, mbTrans[2][1], ExpressionNode.MULTIPLY, fVars[1])) .plus(mbTrans[2][2]); ExpressionNode newX = new ExpressionNode(kernel, mbTrans[0][0], ExpressionNode.MULTIPLY, fVars[0]) .plus(new ExpressionNode(kernel, mbTrans[0][1], ExpressionNode.MULTIPLY, fVars[1])) .plus(mbTrans[0][2]); ExpressionNode newY = new ExpressionNode(kernel, mbTrans[1][0], ExpressionNode.MULTIPLY, fVars[0]) .plus(new ExpressionNode(kernel, mbTrans[1][1], ExpressionNode.MULTIPLY, fVars[1])) .plus(mbTrans[1][2]); expression = expression.replaceAndWrap(fVars[1], newY.divide(newZ)); expression = expression.replaceAndWrap(dummy, newX.divide(newZ)); this.initIneqs(expression, this); }
// replace every x in tree by (x - vx) // i.e. replace fVar with (fvar - vx) private void translateX(ExpressionNode en, double vx, int varNo) { ExpressionValue left = en.getLeft(); ExpressionValue right = en.getRight(); // left tree if (left == fVars[varNo]) { try { // is there a constant number to the right? MyDouble num = (MyDouble) right; double temp; switch (en.getOperation()) { case ExpressionNode.PLUS: temp = num.getDouble() - vx; if (Kernel.isZero(temp)) { expression = expression.replaceAndWrap(en, fVars[varNo]); } else if (temp < 0) { en.setOperation(ExpressionNode.MINUS); num.set(-temp); } else { num.set(temp); } return; case ExpressionNode.MINUS: temp = num.getDouble() + vx; if (Kernel.isZero(temp)) { expression = expression.replaceAndWrap(en, fVars[varNo]); } else if (temp < 0) { en.setOperation(ExpressionNode.PLUS); num.set(-temp); } else { num.set(temp); } return; default: en.setLeft(shiftXnode(vx, varNo)); } } catch (Exception e) { en.setLeft(shiftXnode(vx, varNo)); } } else if (left instanceof ExpressionNode) { translateX((ExpressionNode) left, vx, varNo); } // right tree if (right == fVars[varNo]) { en.setRight(shiftXnode(vx, varNo)); } else if (right instanceof ExpressionNode) { translateX((ExpressionNode) right, vx, varNo); } }
public void matrixTransform(double a00, double a01, double a10, double a11) { ExpressionNode dummy = new ExpressionNode(); expression.replaceAndWrap(fVars[0], dummy); MyDouble ma00 = new MyDouble(kernel, a00); MyDouble ma01 = new MyDouble(kernel, a01); MyDouble ma10 = new MyDouble(kernel, a10); MyDouble ma11 = new MyDouble(kernel, a11); ExpressionNode newX = new ExpressionNode(kernel, ma00, ExpressionNode.MULTIPLY, fVars[0]) .plus(new ExpressionNode(kernel, ma01, ExpressionNode.MULTIPLY, fVars[1])); ExpressionNode newY = new ExpressionNode(kernel, ma10, ExpressionNode.MULTIPLY, fVars[0]) .plus(new ExpressionNode(kernel, ma11, ExpressionNode.MULTIPLY, fVars[1])); expression = expression.replaceAndWrap(fVars[1], newY); expression = expression.replaceAndWrap(dummy, newX); this.initIneqs(expression, this); }
public ExpressionValue replace(ExpressionValue oldOb, ExpressionValue newOb) { expression = expression.replaceAndWrap(oldOb, newOb); return this; }