List of usage examples for org.apache.commons.math3.util FastMath PI
double PI
To view the source code for org.apache.commons.math3.util FastMath PI.
Click Source Link
From source file:fr.cs.examples.conversion.PropagatorConversion.java
/** Program entry point. * @param args program arguments (unused here) *//*from w w w.j a v a 2 s . c o m*/ public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); // gravity field NormalizedSphericalHarmonicsProvider provider = GravityFieldFactory.getNormalizedProvider(2, 0); double mu = provider.getMu(); // inertial frame Frame inertialFrame = FramesFactory.getEME2000(); // Initial date AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC()); // Initial orbit (GTO) final double a = 24396159; // semi major axis in meters final double e = 0.72831215; // eccentricity final double i = FastMath.toRadians(7); // inclination final double omega = FastMath.toRadians(180); // perigee argument final double raan = FastMath.toRadians(261); // right ascention of ascending node final double lM = 0; // mean anomaly Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu); final double period = initialOrbit.getKeplerianPeriod(); // Initial state definition final SpacecraftState initialState = new SpacecraftState(initialOrbit); // Adaptive step integrator with a minimum step of 0.001 and a maximum step of 1000 final double minStep = 0.001; final double maxStep = 1000.; final double dP = 1.e-2; final OrbitType orbType = OrbitType.CARTESIAN; final double[][] tol = NumericalPropagator.tolerances(dP, initialOrbit, orbType); final AbstractIntegrator integrator = new DormandPrince853Integrator(minStep, maxStep, tol[0], tol[1]); // Propagator NumericalPropagator numProp = new NumericalPropagator(integrator); numProp.setInitialState(initialState); numProp.setOrbitType(orbType); // Force Models: // 1 - Perturbing gravity field (only J2 is considered here) ForceModel gravity = new HolmesFeatherstoneAttractionModel( FramesFactory.getITRF(IERSConventions.IERS_2010, true), provider); // Add force models to the propagator numProp.addForceModel(gravity); // Propagator factory PropagatorBuilder builder = new KeplerianPropagatorBuilder(mu, inertialFrame, OrbitType.KEPLERIAN, PositionAngle.TRUE); // Propagator converter PropagatorConverter fitter = new FiniteDifferencePropagatorConverter(builder, 1.e-6, 5000); // Resulting propagator KeplerianPropagator kepProp = (KeplerianPropagator) fitter.convert(numProp, 2 * period, 251); // Step handlers StatesHandler numStepHandler = new StatesHandler(); StatesHandler kepStepHandler = new StatesHandler(); // Set up operating mode for the propagator as master mode // with fixed step and specialized step handler numProp.setMasterMode(60., numStepHandler); kepProp.setMasterMode(60., kepStepHandler); // Extrapolate from the initial to the final date numProp.propagate(initialDate.shiftedBy(10. * period)); kepProp.propagate(initialDate.shiftedBy(10. * period)); // retrieve the states List<SpacecraftState> numStates = numStepHandler.getStates(); List<SpacecraftState> kepStates = kepStepHandler.getStates(); // Print the results on the output file File output = new File(new File(System.getProperty("user.home")), "elements.dat"); PrintStream stream = new PrintStream(output); stream.println("# date Anum Akep Enum Ekep Inum Ikep LMnum LMkep"); for (SpacecraftState numState : numStates) { for (SpacecraftState kepState : kepStates) { if (numState.getDate().compareTo(kepState.getDate()) == 0) { stream.println(numState.getDate() + " " + numState.getA() + " " + kepState.getA() + " " + numState.getE() + " " + kepState.getE() + " " + FastMath.toDegrees(numState.getI()) + " " + FastMath.toDegrees(kepState.getI()) + " " + FastMath.toDegrees(MathUtils.normalizeAngle(numState.getLM(), FastMath.PI)) + " " + FastMath.toDegrees(MathUtils.normalizeAngle(kepState.getLM(), FastMath.PI))); break; } } } stream.close(); System.out.println("Results saved as file " + output); File output1 = new File(new File(System.getProperty("user.home")), "elts_pv.dat"); PrintStream stream1 = new PrintStream(output1); stream.println("# date pxn pyn pzn vxn vyn vzn pxk pyk pzk vxk vyk vzk"); for (SpacecraftState numState : numStates) { for (SpacecraftState kepState : kepStates) { if (numState.getDate().compareTo(kepState.getDate()) == 0) { final double pxn = numState.getPVCoordinates().getPosition().getX(); final double pyn = numState.getPVCoordinates().getPosition().getY(); final double pzn = numState.getPVCoordinates().getPosition().getZ(); final double vxn = numState.getPVCoordinates().getVelocity().getX(); final double vyn = numState.getPVCoordinates().getVelocity().getY(); final double vzn = numState.getPVCoordinates().getVelocity().getZ(); final double pxk = kepState.getPVCoordinates().getPosition().getX(); final double pyk = kepState.getPVCoordinates().getPosition().getY(); final double pzk = kepState.getPVCoordinates().getPosition().getZ(); final double vxk = kepState.getPVCoordinates().getVelocity().getX(); final double vyk = kepState.getPVCoordinates().getVelocity().getY(); final double vzk = kepState.getPVCoordinates().getVelocity().getZ(); stream1.println(numState.getDate() + " " + pxn + " " + pyn + " " + pzn + " " + vxn + " " + vyn + " " + vzn + " " + pxk + " " + pyk + " " + pzk + " " + vxk + " " + vyk + " " + vzk); break; } } } stream1.close(); System.out.println("Results saved as file " + output1); } catch (OrekitException oe) { System.err.println(oe.getLocalizedMessage()); System.exit(1); } catch (FileNotFoundException fnfe) { System.err.println(fnfe.getLocalizedMessage()); System.exit(1); } }
From source file:gentracklets.Propagate.java
public static void main(String[] args) throws OrekitException { // load the data files File data = new File("/home/zittersteijn/Documents/java/libraries/orekit-data.zip"); DataProvidersManager DM = DataProvidersManager.getInstance(); ZipJarCrawler crawler = new ZipJarCrawler(data); DM.clearProviders();// w w w. j av a 2 s . co m DM.addProvider(crawler); // Read in TLE elements File tleFile = new File("/home/zittersteijn/Documents/TLEs/ASTRA20151207.tle"); FileReader TLEfr; Vector<TLE> tles = new Vector<>(); tles.setSize(30); try { // read and save TLEs to a vector TLEfr = new FileReader("/home/zittersteijn/Documents/TLEs/ASTRA20151207.tle"); BufferedReader readTLE = new BufferedReader(TLEfr); Scanner s = new Scanner(tleFile); String line1, line2; TLE2 tle = new TLE2(); int nrOfObj = 4; for (int ii = 1; ii < nrOfObj + 1; ii++) { System.out.println(ii); line1 = s.nextLine(); line2 = s.nextLine(); if (TLE.isFormatOK(line1, line2)) { tles.setElementAt(new TLE(line1, line2), ii); System.out.println(tles.get(ii).toString()); } else { System.out.println("format problem"); } } readTLE.close(); // define a groundstation Frame inertialFrame = FramesFactory.getEME2000(); TimeScale utc = TimeScalesFactory.getUTC(); double longitude = FastMath.toRadians(7.465); double latitude = FastMath.toRadians(46.87); double altitude = 950.; GeodeticPoint station = new GeodeticPoint(latitude, longitude, altitude); Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true); BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, earthFrame); TopocentricFrame staF = new TopocentricFrame(earth, station, "station"); Vector<Orbit> eles = new Vector<>(); eles.setSize(tles.size()); for (int ii = 1; ii < nrOfObj + 1; ii++) { double a = FastMath.pow(Constants.WGS84_EARTH_MU / FastMath.pow(tles.get(ii).getMeanMotion(), 2), (1.0 / 3)); // convert them to orbits Orbit kep = new KeplerianOrbit(a, tles.get(ii).getE(), tles.get(ii).getI(), tles.get(ii).getPerigeeArgument(), tles.get(ii).getRaan(), tles.get(ii).getMeanAnomaly(), PositionAngle.MEAN, inertialFrame, tles.get(ii).getDate(), Constants.WGS84_EARTH_MU); eles.setElementAt(kep, ii); // set up propagators KeplerianPropagator kepler = new KeplerianPropagator(eles.get(ii)); System.out.println("a: " + a); // Initial state definition double mass = 1000.0; SpacecraftState initialState = new SpacecraftState(kep, mass); // Adaptive step integrator // with a minimum step of 0.001 and a maximum step of 1000 double minStep = 0.001; double maxstep = 1000.0; double positionTolerance = 10.0; OrbitType propagationType = OrbitType.KEPLERIAN; double[][] tolerances = NumericalPropagator.tolerances(positionTolerance, kep, propagationType); AdaptiveStepsizeIntegrator integrator = new DormandPrince853Integrator(minStep, maxstep, tolerances[0], tolerances[1]); NumericalPropagator propagator = new NumericalPropagator(integrator); propagator.setOrbitType(propagationType); // set up and add force models double AMR = 4.0; double crossSection = mass * AMR; double Cd = 0.01; double Cr = 0.5; double Co = 0.8; NormalizedSphericalHarmonicsProvider provider = GravityFieldFactory.getNormalizedProvider(4, 4); ForceModel holmesFeatherstone = new HolmesFeatherstoneAttractionModel( FramesFactory.getITRF(IERSConventions.IERS_2010, true), provider); SphericalSpacecraft ssc = new SphericalSpacecraft(crossSection, Cd, Cr, Co); PVCoordinatesProvider sun = CelestialBodyFactory.getSun(); SolarRadiationPressure srp = new SolarRadiationPressure(sun, Constants.WGS84_EARTH_EQUATORIAL_RADIUS, ssc); // propagator.addForceModel(srp); // propagator.addForceModel(holmesFeatherstone); propagator.setInitialState(initialState); // propagate the orbits with steps size and tracklet lenght at several epochs (tracklets) Vector<AbsoluteDate> startDates = new Vector<>(); startDates.setSize(1); startDates.setElementAt(new AbsoluteDate(2016, 1, 26, 20, 00, 00, utc), 0); // set the step size [s] and total length double tstep = 100; double ld = 3; double ls = FastMath.floor(ld * (24 * 60 * 60) / tstep); System.out.println(ls); SpacecraftState currentStateKep = kepler.propagate(startDates.get(0)); SpacecraftState currentStatePer = propagator.propagate(startDates.get(0)); for (int tt = 0; tt < startDates.size(); tt++) { // set up output file String app = tles.get(ii).getSatelliteNumber() + "_" + startDates.get(tt) + ".txt"; // with formatted output File file1 = new File("/home/zittersteijn/Documents/propagate/keplerian/MEO/" + app); File file2 = new File("/home/zittersteijn/Documents/propagate/perturbed/MEO/" + app); file1.createNewFile(); file2.createNewFile(); Formatter fmt1 = new Formatter(file1); Formatter fmt2 = new Formatter(file2); for (int kk = 0; kk < (int) ls; kk++) { AbsoluteDate propDate = startDates.get(tt).shiftedBy(tstep * kk); currentStateKep = kepler.propagate(propDate); currentStatePer = propagator.propagate(propDate); System.out.println(currentStateKep.getPVCoordinates().getPosition() + "\t" + currentStateKep.getDate()); // convert to RADEC coordinates double[] radecKep = conversions.geo2radec(currentStateKep.getPVCoordinates(), staF, inertialFrame, propDate); double[] radecPer = conversions.geo2radec(currentStatePer.getPVCoordinates(), staF, inertialFrame, propDate); // write the orbit to seperate files with the RA, DEC, epoch and fence given AbsoluteDate year = new AbsoluteDate(YEAR, utc); fmt1.format("%.12f %.12f %.12f %d%n", radecKep[0], radecKep[2], (currentStateKep.getDate().durationFrom(year) / (24 * 3600)), (tt + 1)); fmt2.format("%.12f %.12f %.12f %d%n", radecPer[0], radecPer[2], (currentStateKep.getDate().durationFrom(year) / (24 * 3600)), (tt + 1)); } fmt1.flush(); fmt1.close(); fmt2.flush(); fmt2.close(); } double[] radecKep = conversions.geo2radec(currentStateKep.getPVCoordinates(), staF, inertialFrame, new AbsoluteDate(startDates.get(0), ls * tstep)); double[] radecPer = conversions.geo2radec(currentStatePer.getPVCoordinates(), staF, inertialFrame, new AbsoluteDate(startDates.get(0), ls * tstep)); double sig0 = 1.0 / 3600.0 / 180.0 * FastMath.PI; double dRA = radecKep[0] - radecPer[0] / (sig0 * sig0); double dDEC = radecKep[2] - radecPer[2] / (sig0 * sig0); System.out.println(dRA + "\t" + dDEC); } } catch (FileNotFoundException ex) { Logger.getLogger(GenTracklets.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException iox) { Logger.getLogger(GenTracklets.class.getName()).log(Level.SEVERE, null, iox); } }
From source file:gentracklets.conversions.java
public static double[] geo2radec(PVCoordinates obj, TopocentricFrame staF, Frame inertialFrame, AbsoluteDate epoch) {//from www . j av a 2 s.com Vector3D rho = new Vector3D(0, 0, 0); try { rho = obj.getPosition().subtract(staF.getPVCoordinates(epoch, inertialFrame).getPosition()); } catch (OrekitException ex) { Logger.getLogger(conversions.class.getName()).log(Level.SEVERE, null, ex); } double rho_mag = rho.getNorm(); double DEC = FastMath.asin(rho.getZ() / rho_mag); double cosRA = 0.0; double sinRA = 0.0; double RA = 0.0; Vector3D v_site = new Vector3D(0, 0, 0); try { v_site = staF.getPVCoordinates(epoch, inertialFrame).getVelocity(); } catch (OrekitException ex) { Logger.getLogger(conversions.class.getName()).log(Level.SEVERE, null, ex); } Vector3D rhoDot = obj.getVelocity().subtract(v_site); if (FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)) != 0) { cosRA = rho.getX() / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)); sinRA = rho.getY() / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)); RA = FastMath.atan2(sinRA, cosRA); if (RA <= 0) { RA = RA + 2 * FastMath.PI; } } else { sinRA = rhoDot.getY() / FastMath.sqrt(FastMath.pow(rhoDot.getX(), 2) + FastMath.pow(rhoDot.getY(), 2)); cosRA = rhoDot.getX() / FastMath.sqrt(FastMath.pow(rhoDot.getX(), 2) + FastMath.pow(rhoDot.getY(), 2)); RA = FastMath.atan2(sinRA, cosRA); if (RA <= 0) { RA = RA + 2 * FastMath.PI; } } double rhoDot_mag = rho.dotProduct(rhoDot) / rho_mag; double RAdot = (rhoDot.getX() * rho.getY() - rhoDot.getY() * rho.getX()) / (-1 * FastMath.pow(rho.getY(), 2) - FastMath.pow(rho.getX(), 2)); double DECdot = (rhoDot.getZ() - rhoDot_mag * FastMath.sin(DEC)) / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)); double[] out = { RA, RAdot, DEC, DECdot, rho_mag, rhoDot_mag }; return out; }
From source file:com.clust4j.kernel.CircularKernel.java
@Override public double getPartialSimilarity(double[] a, double[] b) { final double lp = toHilbertPSpace(a, b); // Per corner case condition if (lp >= getSigma()) return 0.0; final double twoOverPi = (2d / FastMath.PI); final double lpOverSig = lp / getSigma(); /* Front segment */ final double front = twoOverPi * FastMath.acos(-lpOverSig); /* Back segment */ final double first = twoOverPi * lpOverSig; final double second = FastMath.sqrt(1.0 - FastMath.pow(lpOverSig, 2)); final double back = first * second; final double answer = front - back; return Double.isNaN(answer) ? Double.NEGATIVE_INFINITY : answer; }
From source file:edu.unc.cs.gamma.rvo.Circle.java
private void setupScenario() { // Specify the global time step of the simulation. Simulator.instance.setTimeStep(0.25); // Specify the default parameters for agents that are subsequently // added.//ww w .j a v a 2 s . com Simulator.instance.setAgentDefaults(15.0, 10, 10.0, 10.0, 1.5, 2.0, Vector2D.ZERO); // Add agents, specifying their start position, and store their goals on // the opposite side of the environment. final double angle = 0.008 * FastMath.PI; for (int i = 0; i < 250; i++) { Simulator.instance .addAgent(new Vector2D(FastMath.cos(i * angle), FastMath.sin(i * angle)).scalarMultiply(200.0)); goals.add(Simulator.instance.getAgentPosition(i).negate()); } }
From source file:cloudnet.workloads.PeriodicWorkloadModel.java
@Override protected double generateWorkload(long timestamp) { // workload = lower + diff_upper_lower * ((sin(x) + 1)/2 + deviation) double periodicValue = (FastMath.sin(timestamp * 2 * FastMath.PI / period) + 1) / 2; double randomValue = (2 * (random.nextDouble() - 0.5) * deviation); double workload = lowerThreshold + (upperThreshold - lowerThreshold) * (periodicValue + randomValue); return workload; }
From source file:cloudnet.workloads.OnceInAlifetimeWorkloadModel.java
@Override protected double generateWorkload(long timestamp) { // workload = baseValue, if timestamp <= startTime or timestamp > startTime + period /2 // otherwise workload = periodic workload modelled with sin(x) if (timestamp >= startTime && timestamp < startTime + period / 2) { double periodicValue = FastMath.sin((timestamp - startTime) * 2 * FastMath.PI / period); double workload = baseValue + (peekValue - baseValue) * periodicValue; return workload; } else {//from www .ja v a2 s . c o m return baseValue; } }
From source file:com.cloudera.oryx.rdf.common.information.NumericInformationTest.java
private static double differentialEntropy(StandardDeviation stdev) { return FastMath.log(stdev.getResult() * FastMath.sqrt(2.0 * FastMath.PI * FastMath.E)); }
From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Cheby1.java
private Cheby1(int n, double Rp, double[] W, boolean digital, boolean stop) { super(W, digital, stop); if (Rp < 0) { throw new IllegalArgumentException("cheby1: passband ripple must be positive decibels"); }//from ww w . j a va2 s .c o m this.Rp = Rp; //## Generate splane poles and zeros for the chebyshev type 1 filter final double C = 1; //# default cutoff frequency final double epsilon = FastMath.sqrt(FastMath.pow(10, (Rp / 10)) - 1); final double v0 = FastMath.asinh(1 / epsilon) / n; pole = new Complex[n]; for (int i = 0; i < n; i++) { final Complex p = new Complex(0, FastMath.PI * (2.0 * i - n + 1.0) / (2.0 * n)).exp(); //TODO richtig ??? pole[i] = new Complex(-FastMath.sinh(v0) * p.getReal()) .add(IMAG_ONE.multiply(FastMath.cosh(v0)).multiply(p.getImaginary())); } zero = new Complex[0]; //## compensate for amplitude at s=0 Complex gainC = OctaveBuildIn.prod(OctaveBuildIn.neg(pole)); //## if n is even, the ripple starts low, but if n is odd the ripple //## starts high. We must adjust the s=0 amplitude to compensate. if (n % 2 == 0) { gainC = gainC.divide(FastMath.pow(10, Rp / 20)); } gain = gainC.getReal(); }
From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Cheby2.java
private Cheby2(int n, double Rs, double[] W, boolean digital, boolean stop) { super(W, digital, stop); if (Rs < 0) { throw new IllegalArgumentException("cheby2: stopband attenuation must be positive decibels"); }/*from w w w . ja v a 2 s . com*/ this.Rs = Rs; //## Generate splane poles and zeros for the chebyshev type 2 filter //## From: Stearns, SD; David, RA; (1988). Signal Processing Algorithms. //## New Jersey: Prentice-Hall. int C = 1; //# default cutoff frequency final double lambda = FastMath.pow(10, Rs / 20); final double phi = FastMath.log(lambda + FastMath.sqrt(FastMath.pow(lambda, 2) - 1)) / n; final double[] theta = new double[n]; final double[] alpha = new double[n]; final double[] beta = new double[n]; for (int i = 0; i < n; i++) { theta[i] = FastMath.PI * (i + 0.5) / n; alpha[i] = -FastMath.sinh(phi) * FastMath.sin(theta[i]); beta[i] = FastMath.cosh(phi) * FastMath.cos(theta[i]); } final Complex IMAG_ONE = new Complex(0.0, 1); if (n % 2 != 0) { //## drop theta==pi/2 since it results in a zero at infinity zero = new Complex[n - 1]; for (int i = 0; i < n / 2; i++) { zero[i] = IMAG_ONE.multiply(C / FastMath.cos(theta[i])); } for (int i = n / 2 + 1; i < n; i++) { zero[i - 1] = IMAG_ONE.multiply(C / FastMath.cos(theta[i])); } } else { zero = new Complex[n]; for (int i = 0; i < n; i++) { zero[i] = IMAG_ONE.multiply(C / FastMath.cos(theta[i])); } } pole = new Complex[n]; for (int i = 0; i < n; i++) { pole[i] = new Complex(C / (FastMath.pow(alpha[i], 2) + FastMath.pow(beta[i], 2))) .multiply(new Complex(alpha[i], -beta[i])); } /* ## Compensate for amplitude at s=0 ## Because of the vagaries of floating point computations, the ## prod(pole)/prod(zero) sometimes comes out as negative and ## with a small imaginary component even though analytically ## the gain will always be positive, hence the abs(real(...)) */ gain = FastMath.abs(OctaveBuildIn.prod(pole).divide(OctaveBuildIn.prod(zero)).getReal()); }