List of usage examples for org.apache.commons.math3.util FastMath tan
public static double tan(double x)
From source file:cc.redberry.core.number.ComplexUtils.java
/** * Numeric tangent form complex number.//from www . j av a2 s. c om * * @param complex argument * @return tangent */ public static Complex tan(Complex complex) { if (complex.isReal()) return new Complex(FastMath.tan(complex.getReal().doubleValue())); return new Complex(new org.apache.commons.math3.complex.Complex(complex.getReal().doubleValue(), complex.getImaginary().doubleValue()).tan()); }
From source file:cc.redberry.core.number.ComplexUtils.java
/** * Numeric cotangent form complex number. * * @param complex argument/*w ww .j av a 2 s .com*/ * @return cotangent */ public static Complex cot(Complex complex) { if (complex.isReal()) return new Complex(1 / FastMath.tan(complex.getReal().doubleValue())); return new Complex(new org.apache.commons.math3.complex.Complex(complex.getReal().doubleValue(), complex.getImaginary().doubleValue()).tan().reciprocal()); }
From source file:mase.app.foraging.FlyingRobot.java
public FlyingRobot(ForagingTask sim, Continuous2D field, AgentController ac) { super(sim, field, sim.par.flyingRadius, COLOR, ac); if (sim.par.flyingStartHeight < 5) { this.setCollidableTypes(EmboddiedAgent.class); }//from w w w .j ava 2s . c o m this.enableBoundedArena(false); effector = new FlyingEffector(sim, field, this); super.addEffector(effector); effector.enableAltitude(sim.par.flyingVerticalMovement); effector.setHeight(sim.par.flyingStartHeight); effector.setMaxHeight(sim.par.flyingMaxHeight); effector.setAccelerationLimits(sim.par.flyingLinearAcc, sim.par.flyingAngAcc); effector.calculateDragCoefficients(sim.par.flyingLinearSpeed, sim.par.flyingAngSpeed); effector.setNoise(sim.par.actuatorNoise); double vRange = sim.par.flyingStartHeight * FastMath.tan(sim.par.flyingVisionAngle / 2); itemArcs = new DistanceSensorArcs(sim, field, this); super.addSensor(itemArcs); itemArcs.centerToCenter(true); itemArcs.setRange(vRange); itemArcs.setArcs(sim.par.flyingArcs); itemArcs.setBinary(false); itemArcs.setObjectTypes(Item.class); itemArcs.setNoise(sim.par.sensorRangeNoise, sim.par.sensorAngleNoise, DistanceSensorArcs.UNIFORM); botArcs = new DistanceSensorArcs(sim, field, this); super.addSensor(botArcs); botArcs.centerToCenter(true); botArcs.setRange(vRange); botArcs.setArcs(sim.par.flyingArcs); botArcs.setBinary(false); botArcs.setObjectTypes(LandRobot.class); botArcs.setNoise(sim.par.sensorRangeNoise, sim.par.sensorAngleNoise, DistanceSensorArcs.UNIFORM); if (sim.par.flyingVerticalMovement) { HeightSensor hs = new HeightSensor(sim, field, this); hs.setFlyingEffector(effector); hs.setNoise(sim.par.sensorRangeNoise); super.addSensor(hs); effector.updateHeight(); } centre = new RangeBearingSensor(sim, field, this); centre.setObjects(Collections.singletonList( new PointObject(field, new Double2D(sim.par.arenaSize.x / 2, sim.par.arenaSize.y / 2)))); centre.setRange(Double.POSITIVE_INFINITY); centre.setNoise(sim.par.sensorRangeNoise, sim.par.sensorAngleNoise, DistanceSensorArcs.UNIFORM); super.addSensor(centre); }
From source file:mase.app.foraging.LandRobot.java
public LandRobot(ForagingTask sim, Continuous2D field, AgentController ac) { super(sim, field, sim.par.landRadius, Color.BLUE, ac); if (sim.par.flyingStartHeight < 5) { this.setCollidableTypes(EmboddiedAgent.class); }/*from www . j a va2s . c om*/ this.enableBoundedArena(false); //this.setOrientationShowing(false); // movement effector dm = new DashMovementEffector(sim, field, this); super.addEffector(dm); dm.allowBackwardMove(false); dm.setSpeeds(sim.par.landLinearSpeed, sim.par.landTurnSpeed); dm.setNoise(sim.par.actuatorNoise, sim.par.actuatorNoise); itemArcs = new DistanceSensorArcs(sim, field, this); super.addSensor(itemArcs); itemArcs.setRange(sim.par.landSensingRange); itemArcs.setArcs(sim.par.landArcs); itemArcs.setBinary(true); itemArcs.setObjectTypes(Item.class); itemArcs.setNoise(sim.par.sensorRangeNoise, sim.par.sensorAngleNoise, DistanceSensorArcs.UNIFORM); botArcs = new DistanceSensorArcs(sim, field, this); super.addSensor(botArcs); botArcs.centerToCenter(true); double vRange = sim.par.flyingStartHeight * FastMath.tan(sim.par.flyingVisionAngle / 2); botArcs.setRange(vRange); botArcs.setArcs(sim.par.landArcs); botArcs.setBinary(true); botArcs.setObjectTypes(FlyingRobot.class); botArcs.setNoise(sim.par.sensorRangeNoise, sim.par.sensorAngleNoise, DistanceSensorArcs.UNIFORM); }
From source file:net.nicoulaj.benchmarks.math.DoubleTan.java
@GenerateMicroBenchmark public void commonsmath(BlackHole hole) { for (int i = 0; i < data.length - 1; i++) hole.consume(FastMath.tan(data[i])); }
From source file:com.bc.jexp.impl.DefaultNamespace.java
private void registerDefaultFunctions() { registerFunction(new AbstractFunction.D("sin", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.sin(args[0].evalD(env)); }//from ww w. j av a 2s. co m }); registerFunction(new AbstractFunction.D("cos", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.cos(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("tan", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.tan(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("asin", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.asin(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("acos", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.acos(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("atan", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.atan(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("atan2", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.atan2(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.D("log", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.log(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("log10", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.log10(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("exp", 1) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.exp(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("exp10", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return FastMath.pow(10.0, args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("sqr", 1) { public double evalD(final EvalEnv env, final Term[] args) { double v = args[0].evalD(env); return v * v; } }); registerFunction(new AbstractFunction.D("sqrt", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.sqrt(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("pow", 2) { public double evalD(final EvalEnv env, final Term[] args) { return FastMath.pow(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.I("min", 2) { public int evalI(final EvalEnv env, final Term[] args) { return Math.min(args[0].evalI(env), args[1].evalI(env)); } }); registerFunction(new AbstractFunction.D("min", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.min(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.I("max", 2) { public int evalI(final EvalEnv env, final Term[] args) { return Math.max(args[0].evalI(env), args[1].evalI(env)); } }); registerFunction(new AbstractFunction.D("max", 2) { public double evalD(final EvalEnv env, final Term[] args) { return Math.max(args[0].evalD(env), args[1].evalD(env)); } }); registerFunction(new AbstractFunction.D("floor", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.floor(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("round", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.round(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("ceil", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.ceil(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("rint", 1) { public double evalD(EvalEnv env, Term[] args) throws EvalException { return Math.rint(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.I("sign", 1) { public int evalI(final EvalEnv env, final Term[] args) { return ExtMath.sign(args[0].evalI(env)); } }); registerFunction(new AbstractFunction.D("sign", 1) { public double evalD(final EvalEnv env, final Term[] args) { return ExtMath.sign(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.I("abs", 1) { public int evalI(final EvalEnv env, final Term[] args) { return Math.abs(args[0].evalI(env)); } }); registerFunction(new AbstractFunction.D("abs", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.abs(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("deg", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.toDegrees(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("rad", 1) { public double evalD(final EvalEnv env, final Term[] args) { return Math.toRadians(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("ampl", 2) { public double evalD(final EvalEnv env, final Term[] args) { final double a = args[0].evalD(env); final double b = args[1].evalD(env); return Math.sqrt(a * a + b * b); } }); registerFunction(new AbstractFunction.D("phase", 2) { public double evalD(final EvalEnv env, final Term[] args) { final double a = args[0].evalD(env); final double b = args[1].evalD(env); return Math.atan2(b, a); } }); registerFunction(new AbstractFunction.B("feq", 2) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); return ExtMath.feq(x1, x2, EPS); } }); registerFunction(new AbstractFunction.B("feq", 3) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); final double eps = args[2].evalD(env); return ExtMath.feq(x1, x2, eps); } }); registerFunction(new AbstractFunction.B("fneq", 2) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); return ExtMath.fneq(x1, x2, EPS); } }); registerFunction(new AbstractFunction.B("fneq", 3) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { final double x1 = args[0].evalD(env); final double x2 = args[1].evalD(env); final double eps = args[2].evalD(env); return ExtMath.fneq(x1, x2, eps); } }); registerFunction(new AbstractFunction.B("inf", 1) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { return Double.isInfinite(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.B("nan", 1) { public boolean evalB(EvalEnv env, Term[] args) throws EvalException { return Double.isNaN(args[0].evalD(env)); } }); registerFunction(new AbstractFunction.D("distance", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; final int n = args.length / 2; for (int i = 0; i < n; i++) { final double v = args[i + n].evalD(env) - args[i].evalD(env); sqrSum += v * v; } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.D("distance_deriv", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; final int n = args.length / 2; for (int i = 0; i < n - 1; i++) { final double v1 = args[i + 1].evalD(env) - args[i].evalD(env); final double v2 = args[i + n + 1].evalD(env) - args[i + n].evalD(env); sqrSum += (v1 - v2) * (v1 - v2); } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.D("distance_integ", -1) { public double evalD(final EvalEnv env, final Term[] args) { double sqrSum = 0.0; double v1Sum = 0.0; double v2Sum = 0.0; final int n = args.length / 2; for (int i = 0; i < n; i++) { v1Sum += args[i].evalD(env); v2Sum += args[i + n].evalD(env); sqrSum += (v2Sum - v1Sum) * (v2Sum - v1Sum); } return Math.sqrt(sqrSum); } }); registerFunction(new AbstractFunction.B("inrange", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = n1 + args.length / 3; for (int i = 0; i < n1; i++) { final double v = args[i].evalD(env); final double v1 = args[i + n1].evalD(env); final double v2 = args[i + n2].evalD(env); if (v < v1 || v > v2) { return false; } } return true; } }); registerFunction(new AbstractFunction.B("inrange_deriv", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = 2 * n1; for (int i = 0; i < n1 - 1; i++) { final double v = args[i + 1].evalD(env) - args[i].evalD(env); final double v1 = args[i + n1 + 1].evalD(env) - args[i + n1].evalD(env); final double v2 = args[i + n2 + 1].evalD(env) - args[i + n2].evalD(env); if (v < v1 || v > v2) { return false; } } return true; } }); registerFunction(new AbstractFunction.B("inrange_integ", -1) { public boolean evalB(final EvalEnv env, final Term[] args) { final int n1 = args.length / 3; final int n2 = 2 * n1; double vSum = 0.0; double v1Sum = 0.0; double v2Sum = 0.0; for (int i = 0; i < n1; i++) { vSum += args[i].evalD(env); v1Sum += args[i + n1].evalD(env); v2Sum += args[i + n2].evalD(env); if (vSum < v1Sum || vSum > v2Sum) { return false; } } return true; } }); }
From source file:mase.app.foraging.FlyingEffector.java
public void updateHeight() { ForagingTask ft = (ForagingTask) super.state; // Update flying bot sensors double vr = height > maxHeight ? 0 : height * FastMath.tan(ft.par.flyingVisionAngle / 2); for (Sensor sens : ((SmartAgent) ag).getSensors()) { if (sens instanceof DistanceSensorArcs) { DistanceSensorArcs dsa = (DistanceSensorArcs) sens; dsa.setRange(vr);/*w w w .j a v a 2 s . c o m*/ } } // Update land bot sensors double lr = height > maxHeight ? 0 : height * FastMath.tan(ft.par.landVisionAngle / 2); DistanceSensorArcs sens = (DistanceSensorArcs) ft.landBot.getSensors().get(1); sens.setRange(lr); // Update apperance double newScale = MIN_SCALE + (ft.par.flyingRadius * 2 - MIN_SCALE) * ((-Math.min(height, maxHeight) + maxHeight) / maxHeight); OvalPortrayal2D child = (OvalPortrayal2D) ag.getChild(null); child.scale = newScale; if (height < 0.1) { child.paint = Color.BLACK; } else if (height > maxHeight) { child.paint = Color.ORANGE; } else { child.paint = FlyingRobot.COLOR; } if (height < 5) { ag.setCollidableTypes(EmboddiedAgent.class); ft.landBot.setCollidableTypes(EmboddiedAgent.class); } else { ag.setCollidableTypes(); ft.landBot.setCollidableTypes(); } }
From source file:com.wwidesigner.geometry.calculation.DefaultHoleCalculator.java
@Override public TransferMatrix calcTransferMatrix(Hole hole, boolean isOpen, double waveNumber, PhysicalParameters parameters) { double radius = mFudgeFactor * hole.getDiameter() / 2; double boreRadius = hole.getBoreDiameter() / 2; Complex Ys = Complex.ZERO; // Shunt admittance == 1/Zs Complex Za = Complex.ZERO; // Series impedance double Z0h = parameters.calcZ0(radius); double delta = radius / boreRadius; double delta2 = delta * delta; // double Z0 = parameters.calcZ0(boreRadius); // Z0 == Z0h * delta*delta double tm = (radius * delta / 8.) * (1. + 0.207 * delta * delta2); double te = hole.getHeight() + tm; double ta = 0.; // Complex Gamma = Complex.I.multiply(wave_number); if (isOpen) { double kb = waveNumber * radius; double ka = waveNumber * boreRadius; ta = (-0.35 + 0.06 * FastMath.tanh(2.7 * hole.getHeight() / radius)) * radius * delta2; Complex Zr = new Complex(0.25 * kb * kb, (0.822 - 0.47 * FastMath.pow(radius / (boreRadius + hole.getHeight()), 0.8)) * waveNumber * radius);/* w w w .ja v a 2 s. c o m*/ double cos = FastMath.cos(waveNumber * te); Complex jsin = new Complex(0, FastMath.sin(waveNumber * te)); Complex Zo = (Zr.multiply(cos).add(jsin)).divide(Zr.multiply(jsin).add(cos)); double ti = radius * (0.822 + delta * (-0.095 + delta * (-1.566 + delta * (2.138 + delta * (-1.640 + delta * 0.502))))) * (1. + (1. - 4.56 * delta + 6.55 * delta2) * ka * (0.17 + ka * (0.92 + ka * (0.16 - 0.29 * ka)))); Ys = Complex.ONE.divide(Complex.I.multiply(waveNumber * ti).add(Zo).multiply(Z0h)); } else if (hole.getKey() == null) { // Tonehole closed by player's finger. if (hole.getHeight() <= AssumedFingerSize) { // Finger is likely to fill the hole. Ignore the hole entirely. ta = 0.; Ys = Complex.ZERO; } else { ta = (-0.12 - 0.17 * FastMath.tanh(2.4 * (hole.getHeight() - AssumedFingerSize) / radius)) * radius * delta2; Ys = Complex.valueOf(0, FastMath.tan(waveNumber * (te - AssumedFingerSize)) / Z0h); } } else { // Tonehole closed by key. ta = (-0.12 - 0.17 * FastMath.tanh(2.4 * hole.getHeight() / radius)) * radius * delta2; Ys = Complex.valueOf(0, FastMath.tan(waveNumber * te) / Z0h); } Za = Complex.I.multiply(Z0h * delta2 * waveNumber * ta); Complex Za_Zs = Za.multiply(Ys); Complex A = Za_Zs.divide(2.).add(1.); Complex B = Za.multiply(Za_Zs.divide(4.).add(1.)); Complex C = Ys; // Choose A and D to make the determinant = 1. // Complex A = Complex.ONE.add(B.multiply(C)).sqrt(); TransferMatrix result = new TransferMatrix(A, B, C, A); // assert result.determinant() == Complex.ONE; return result; }
From source file:com.ibm.bi.dml.runtime.functionobjects.Builtin.java
public double execute(double in) throws DMLRuntimeException { switch (bFunc) { case SIN://from ww w . j av a 2s. c o m return FASTMATH ? FastMath.sin(in) : Math.sin(in); case COS: return FASTMATH ? FastMath.cos(in) : Math.cos(in); case TAN: return FASTMATH ? FastMath.tan(in) : Math.tan(in); case ASIN: return FASTMATH ? FastMath.asin(in) : Math.asin(in); case ACOS: return FASTMATH ? FastMath.acos(in) : Math.acos(in); case ATAN: return Math.atan(in); //faster in Math case CEIL: return FASTMATH ? FastMath.ceil(in) : Math.ceil(in); case FLOOR: return FASTMATH ? FastMath.floor(in) : Math.floor(in); case LOG: //if ( in <= 0 ) // throw new DMLRuntimeException("Builtin.execute(): logarithm can only be computed for non-negative numbers (input = " + in + ")."); // for negative numbers, Math.log will return NaN return FASTMATH ? FastMath.log(in) : Math.log(in); case LOG_NZ: return (in == 0) ? 0 : FASTMATH ? FastMath.log(in) : Math.log(in); case ABS: return Math.abs(in); //no need for FastMath case SQRT: //if ( in < 0 ) // throw new DMLRuntimeException("Builtin.execute(): squareroot can only be computed for non-negative numbers (input = " + in + ")."); return Math.sqrt(in); //faster in Math case PLOGP: if (in == 0.0) return 0.0; else if (in < 0) return Double.NaN; else return (in * (FASTMATH ? FastMath.log(in) : Math.log(in))); case EXP: return FASTMATH ? FastMath.exp(in) : Math.exp(in); case ROUND: return Math.round(in); //no need for FastMath case SPROP: //sample proportion: P*(1-P) return in * (1 - in); case SIGMOID: //sigmoid: 1/(1+exp(-x)) return FASTMATH ? 1 / (1 + FastMath.exp(-in)) : 1 / (1 + Math.exp(-in)); case SELP: //select positive: x*(x>0) return (in > 0) ? in : 0; default: throw new DMLRuntimeException("Builtin.execute(): Unknown operation: " + bFunc); } }
From source file:edu.mit.fss.examples.visual.gui.WorldWindVisualization.java
@Override public void objectChanged(ObjectChangeEvent event) { if (event.getObject() instanceof Element) { final Element element = (Element) event.getObject(); try {/*www . j a v a 2 s . com*/ SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { if (element.getFrame() == ReferenceFrame.UNKNOWN) { // do not consider elements with missing frame return; } // update position and size for shapes if (element instanceof OrbitalElement) { final OrbitalElement orbital = (OrbitalElement) element; // determine cartesian position of element Vector3D cartPosition = null; try { Transform t = orbital.getFrame().getOrekitFrame().getTransformTo(wwj, date); cartPosition = t.transformPosition(orbital.getPosition()); } catch (OrekitException e) { logger.error(e); } // convert cartesian to geodetic position final Position geoPosition = wwd.getModel().getGlobe() .computePositionFromPoint(convert(cartPosition)); // compute footprint radius using field-of-view angle double earthRadius = wwd.getModel().getGlobe().getRadiusAt(geoPosition.getLatitude(), geoPosition.getLongitude()); final double footRadius = FastMath.max(0, FastMath.min(earthRadius, geoPosition.getElevation() * FastMath .tan(FastMath.toRadians(optionsPanel.getFieldOfView(orbital) / 2)))); optionsPanel.getOrbitalShape(orbital).setCenterPosition(geoPosition); optionsPanel.getFootprintShape(orbital) .setCenter(new LatLon(geoPosition.getLatitude(), geoPosition.getLongitude())); optionsPanel.getFootprintShape(orbital).setMajorRadius(footRadius); optionsPanel.getFootprintShape(orbital).setMinorRadius(footRadius); } else if (element instanceof SurfaceElement) { final SurfaceElement surface = (SurfaceElement) element; optionsPanel.getSurfaceMarker(surface).setPosition(Position.fromDegrees( surface.getLatitude(), surface.getLongitude(), surface.getAltitude())); } } }); } catch (InvocationTargetException | InterruptedException e) { logger.error(e); } } }