List of usage examples for org.apache.commons.math.analysis.polynomials PolynomialFunction multiply
public PolynomialFunction multiply(final PolynomialFunction p)
From source file:geogebra.kernel.AlgoIntersectPolynomialConic.java
@Override protected void compute() { double[] A = c.matrix; if (h.isPolynomialFunction(false)) { PolyFunction pf = h.getFunction().getNumericPolynomialDerivative(0); PolynomialFunction y = new PolynomialFunction(pf.getCoeffs()); PolynomialFunction r = new PolynomialFunction(new double[] { A[2], 2 * A[4], A[0] }); r = r.add(y.multiply(new PolynomialFunction(new double[] { 2 * A[5], 2 * A[3] }))); r = r.add(y.multiply(y.multiply(new PolynomialFunction(new double[] { A[1] })))); //Application.debug("r = "+r.toString()); setRootsPolynomial(r);// ww w .j a va 2 s. c o m } else { Kernel ker = cons.getKernel(); GeoFunction substituteFunctionX = null; ker.setSilentMode(true); /*try { substituteFunctionX = (GeoFunction) ker.getAlgebraProcessor().processValidExpression( ker.getParser().parseGeoGebraExpression("x"))[0]; } catch (MyError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ GeoImplicitPoly iPoly = new GeoImplicitPoly(cons); c.toGeoImplicitPoly(iPoly); GeoFunction paramEquation = new GeoFunction(cons, iPoly, null, h); double nroots = 0; double res[] = new double[2]; if (c.getType() == GeoConicND.CONIC_CIRCLE || c.getType() == GeoConicND.CONIC_ELLIPSE) { nroots = kernel.getEquationSolver().solveQuadratic(new double[] { -A[5] * A[5] + A[1] * A[2], 2 * (A[1] * A[4] - A[3] * A[5]), A[0] * A[1] - A[3] * A[3] }, res); } AlgoRoots algo = null; if (nroots == 2) { //assume res[0]>=res[1] if (res[1] > res[0]) { double temp = res[0]; res[0] = res[1]; res[1] = temp; } algo = new AlgoRoots(cons, paramEquation, new GeoNumeric(cons, Math.max(res[1] - Kernel.MIN_PRECISION, h.getMinParameter())), new GeoNumeric(cons, Math.min(res[0] + Kernel.MIN_PRECISION, h.getMaxParameter()))); } else { algo = new AlgoRoots(cons, paramEquation, new GeoNumeric(cons, h.getMinParameter()), new GeoNumeric(cons, h.getMaxParameter())); } GeoPoint[] points = algo.getRootPoints(); List<double[]> valPairs = new ArrayList<double[]>(); for (int i = 0; i < points.length; i++) { double t = points[i].getX(); valPairs.add(new double[] { t, h.evaluate(t) }); } ker.setSilentMode(false); setPoints(valPairs); return; } }
From source file:geogebra.common.kernel.algos.AlgoIntersectPolynomialConic.java
@Override public void compute() { double[] A = c.getFlatMatrix(); if (h.isPolynomialFunction(false)) { PolyFunction pf = h.getFunction().getNumericPolynomialDerivative(0, false); PolynomialFunction y = new PolynomialFunction(pf.getCoeffs()); PolynomialFunction r = new PolynomialFunction(new double[] { A[2], 2 * A[4], A[0] }); r = r.add(y.multiply(new PolynomialFunction(new double[] { 2 * A[5], 2 * A[3] }))); r = r.add(y.multiply(y.multiply(new PolynomialFunction(new double[] { A[1] })))); // Application.debug("r = "+r.toString()); setRootsPolynomial(r);/*w w w . ja va 2 s . co m*/ } else { Kernel ker = cons.getKernel(); ker.setSilentMode(true); /* * try { substituteFunctionX = (GeoFunction) * ker.getAlgebraProcessor().processValidExpression( * ker.getParser().parseGeoGebraExpression("x"))[0]; } catch * (MyError e) { // TODO Auto-generated catch block * e.printStackTrace(); } catch (ParseException e) { // TODO * Auto-generated catch block e.printStackTrace(); } catch * (Exception e) { // TODO Auto-generated catch block * e.printStackTrace(); } */ GeoImplicitPoly iPoly = new GeoImplicitPoly(cons); c.toGeoImplicitPoly(iPoly); GeoFunction paramEquation = new GeoFunction(cons, iPoly, null, h); double nroots = 0; double res[] = new double[2]; if (c.getType() == GeoConicNDConstants.CONIC_CIRCLE || c.getType() == GeoConicNDConstants.CONIC_ELLIPSE) { nroots = kernel.getEquationSolver().solveQuadratic(new double[] { -A[5] * A[5] + A[1] * A[2], 2 * (A[1] * A[4] - A[3] * A[5]), A[0] * A[1] - A[3] * A[3] }, res, Kernel.STANDARD_PRECISION); } AlgoRoots algo = null; if (nroots == 2) { // assume res[0]>=res[1] if (res[1] > res[0]) { double temp = res[0]; res[0] = res[1]; res[1] = temp; } algo = new AlgoRoots(cons, paramEquation, new GeoNumeric(cons, Math.max(res[1] - Kernel.MIN_PRECISION, h.getMinParameter())), new GeoNumeric(cons, Math.min(res[0] + Kernel.MIN_PRECISION, h.getMaxParameter()))); } else { algo = new AlgoRoots(cons, paramEquation, new GeoNumeric(cons, h.getMinParameter()), new GeoNumeric(cons, h.getMaxParameter())); } GeoPoint[] points = algo.getRootPoints(); List<double[]> valPairs = new ArrayList<double[]>(); for (int i = 0; i < points.length; i++) { double t = points[i].getX(); valPairs.add(new double[] { t, h.evaluate(t) }); } ker.setSilentMode(false); setPoints(valPairs); return; } }
From source file:geogebra.kernel.AlgoIntersectImplicitpolyParametric.java
@Override protected void compute() { if (p == null || !p.isDefined()) { return;//from w ww . j ava2 s . com } if (f != null) { if (!f.isPolynomialFunction(false) || !f.isDefined) { return; } tx = new PolynomialFunction(new double[] { 0, 1 }); //x=t ty = new PolynomialFunction(f.fun.getNumericPolynomialDerivative(0).getCoeffs()); //y=f(t) } else if (l != null) { if (!l.isDefined()) { return; } //get parametrisation of line double startP[] = new double[2]; l.getInhomPointOnLine(startP); tx = new PolynomialFunction(new double[] { startP[0], l.getY() }); //x=p1+t*r1 ty = new PolynomialFunction(new double[] { startP[1], -l.getX() }); //x=p1+t*r1 } else { return; } PolynomialFunction sum = null; PolynomialFunction zs = null; //Insert x and y (univariat)polynomials via the Horner-scheme double[][] coeff = p.getCoeff(); if (coeff != null) for (int i = coeff.length - 1; i >= 0; i--) { zs = new PolynomialFunction(new double[] { coeff[i][coeff[i].length - 1] }); for (int j = coeff[i].length - 2; j >= 0; j--) { zs = zs.multiply(ty).add(new PolynomialFunction(new double[] { coeff[i][j] }));//y*zs+coeff[i][j]; } if (sum == null) sum = zs; else sum = sum.multiply(tx).add(zs);//sum*x+zs; } setRootsPolynomial(sum); }
From source file:geogebra.kernel.implicit.AlgoIntersectImplicitpolyParametric.java
@Override protected void compute() { if (!p.isDefined()) { return;/*from w ww .j a v a 2s. c o m*/ } double maxT; double minT; if (f != null) { if (!f.isDefined()) { return; } if (!f.isPolynomialFunction(false)) { Kernel ker = cons.getKernel(); ker.setSilentMode(true); GeoFunction paramEquation = new GeoFunction(cons, p, null, f); AlgoRoots algo = new AlgoRoots(cons, paramEquation, new GeoNumeric(cons, f.getMinParameter()), new GeoNumeric(cons, f.getMaxParameter())); GeoPoint[] points = algo.getRootPoints(); List<double[]> valPairs = new ArrayList<double[]>(); for (int i = 0; i < points.length; i++) { double t = points[i].getX(); valPairs.add(new double[] { t, f.evaluate(t) }); } ker.setSilentMode(false); setPoints(valPairs); return; } tx = new PolynomialFunction(new double[] { 0, 1 }); //x=t ty = new PolynomialFunction(f.getFunction().getNumericPolynomialDerivative(0).getCoeffs()); //y=f(t) maxT = f.getMaxParameter(); minT = f.getMinParameter(); } else if (l != null) { if (!l.isDefined()) { points.adjustOutputSize(0); return; } //get parametrisation of line double startP[] = new double[2]; l.getInhomPointOnLine(startP); tx = new PolynomialFunction(new double[] { startP[0], l.getY() }); //x=p1+t*r1 ty = new PolynomialFunction(new double[] { startP[1], -l.getX() }); //y=p2+t*r2 maxT = l.getMaxParameter(); minT = l.getMinParameter(); if (l.getParentAlgorithm() instanceof AlgoTangentImplicitpoly) { tangentPoints = ((AlgoTangentImplicitpoly) l.getParentAlgorithm()).getTangentPoints(); } } else { return; } PolynomialFunction sum = null; PolynomialFunction zs = null; //Insert x and y (univariat)polynomials via the Horner-scheme double[][] coeff = p.getCoeff(); if (coeff != null) for (int i = coeff.length - 1; i >= 0; i--) { zs = new PolynomialFunction(new double[] { coeff[i][coeff[i].length - 1] }); for (int j = coeff[i].length - 2; j >= 0; j--) { zs = zs.multiply(ty).add(new PolynomialFunction(new double[] { coeff[i][j] }));//y*zs+coeff[i][j]; } if (sum == null) sum = zs; else sum = sum.multiply(tx).add(zs);//sum*x+zs; } setRootsPolynomialWithinRange(sum, minT, maxT); mergeWithTangentPoints(); }
From source file:geogebra.common.kernel.implicit.AlgoIntersectImplicitpolyParametric.java
@Override public void compute() { if (!p.isDefined()) { return;/*from w w w . j av a 2 s . c o m*/ } double maxT; double minT; if (f != null) { if (!f.isDefined()) { return; } if (!f.isPolynomialFunction(false)) { Kernel ker = cons.getKernel(); ker.setSilentMode(true); GeoFunction paramEquation = new GeoFunction(cons, p, null, f); AlgoRoots algo = new AlgoRoots(cons, paramEquation, new GeoNumeric(cons, f.getMinParameter()), new GeoNumeric(cons, f.getMaxParameter())); GeoPoint[] rootPoints = algo.getRootPoints(); List<double[]> valPairs = new ArrayList<double[]>(); for (int i = 0; i < rootPoints.length; i++) { double t = rootPoints[i].getX(); valPairs.add(new double[] { t, f.evaluate(t) }); } ker.setSilentMode(false); setPoints(valPairs); return; } tx = new PolynomialFunction(new double[] { 0, 1 }); //x=t ty = new PolynomialFunction(f.getFunction().getNumericPolynomialDerivative(0, false).getCoeffs()); //y=f(t) maxT = f.getMaxParameter(); minT = f.getMinParameter(); } else if (l != null) { if (!l.isDefined()) { points.adjustOutputSize(0); return; } //get parametrisation of line double startP[] = new double[2]; l.getInhomPointOnLine(startP); tx = new PolynomialFunction(new double[] { startP[0], l.getY() }); //x=p1+t*r1 ty = new PolynomialFunction(new double[] { startP[1], -l.getX() }); //y=p2+t*r2 maxT = l.getMaxParameter(); minT = l.getMinParameter(); if (l.getParentAlgorithm() instanceof AlgoTangentImplicitpoly) { tangentPoints = ((AlgoTangentImplicitpoly) l.getParentAlgorithm()).getTangentPoints(); } } else { return; } PolynomialFunction sum = null; PolynomialFunction zs = null; //Insert x and y (univariat)polynomials via the Horner-scheme double[][] coeff = p.getCoeff(); if (coeff != null) for (int i = coeff.length - 1; i >= 0; i--) { zs = new PolynomialFunction(new double[] { coeff[i][coeff[i].length - 1] }); for (int j = coeff[i].length - 2; j >= 0; j--) { zs = zs.multiply(ty).add(new PolynomialFunction(new double[] { coeff[i][j] }));//y*zs+coeff[i][j]; } if (sum == null) sum = zs; else sum = sum.multiply(tx).add(zs);//sum*x+zs; } setRootsPolynomialWithinRange(sum, minT, maxT); mergeWithTangentPoints(); }