List of usage examples for org.apache.commons.math3.util FastMath toDegrees
public static double toDegrees(double x)
From source file:fr.cs.examples.propagation.MasterMode.java
/** Program entry point. * @param args program arguments (unused here) *///from w w w . j a va 2s . c om public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); // gravitation coefficient double mu = 3.986004415e+14; // inertial frame Frame inertialFrame = FramesFactory.getEME2000(); // Initial date AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC()); // Initial orbit double a = 24396159; // semi major axis in meters double e = 0.72831215; // eccentricity double i = FastMath.toRadians(7); // inclination double omega = FastMath.toRadians(180); // perigee argument double raan = FastMath.toRadians(261); // right ascention of ascending node double lM = 0; // mean anomaly Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu); // Initial state definition 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.0; final double positionTolerance = 10.0; final OrbitType propagationType = OrbitType.KEPLERIAN; final double[][] tolerances = NumericalPropagator.tolerances(positionTolerance, initialOrbit, propagationType); AdaptiveStepsizeIntegrator integrator = new DormandPrince853Integrator(minStep, maxstep, tolerances[0], tolerances[1]); // Propagator NumericalPropagator propagator = new NumericalPropagator(integrator); propagator.setOrbitType(propagationType); // Force Model (reduced to perturbing gravity field) final NormalizedSphericalHarmonicsProvider provider = GravityFieldFactory.getNormalizedProvider(10, 10); ForceModel holmesFeatherstone = new HolmesFeatherstoneAttractionModel( FramesFactory.getITRF(IERSConventions.IERS_2010, true), provider); // Add force model to the propagator propagator.addForceModel(holmesFeatherstone); // Set up initial state in the propagator propagator.setInitialState(initialState); // Set up operating mode for the propagator as master mode // with fixed step and specialized step handler propagator.setMasterMode(60., new TutorialStepHandler()); // Extrapolate from the initial to the final date SpacecraftState finalState = propagator.propagate(initialDate.shiftedBy(630.)); KeplerianOrbit o = (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(finalState.getOrbit()); System.out.format(Locale.US, "Final state:%n%s %12.3f %10.8f %10.6f %10.6f %10.6f %10.6f%n", finalState.getDate(), o.getA(), o.getE(), FastMath.toDegrees(o.getI()), FastMath.toDegrees(o.getPerigeeArgument()), FastMath.toDegrees(o.getRightAscensionOfAscendingNode()), FastMath.toDegrees(o.getTrueAnomaly())); } catch (OrekitException oe) { System.err.println(oe.getMessage()); } }
From source file:fr.cs.examples.conversion.PropagatorConversion.java
/** Program entry point. * @param args program arguments (unused here) *///from www . j av a2 s. c om 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:fr.cs.examples.attitude.EarthObservation.java
/** Program entry point. * @param args program arguments (unused here) */// w ww.j a va 2 s . com public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); final SortedSet<String> output = new TreeSet<String>(); // Initial state definition : date, orbit final AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC()); final Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680); final Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231); final Orbit initialOrbit = new KeplerianOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), initialDate, Constants.EIGEN5C_EARTH_MU); // Attitudes sequence definition final AttitudeProvider dayObservationLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(40), 0); final AttitudeProvider nightRestingLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH); final PVCoordinatesProvider sun = CelestialBodyFactory.getSun(); final PVCoordinatesProvider earth = CelestialBodyFactory.getEarth(); final EventDetector dayNightEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new ContinueOnEvent<EclipseDetector>()); final EventDetector nightDayEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new ContinueOnEvent<EclipseDetector>()); final AttitudesSequence attitudesSequence = new AttitudesSequence(); final AttitudesSequence.SwitchHandler switchHandler = new AttitudesSequence.SwitchHandler() { public void switchOccurred(AttitudeProvider preceding, AttitudeProvider following, SpacecraftState s) { if (preceding == dayObservationLaw) { output.add(s.getDate() + ": switching to night law"); } else { output.add(s.getDate() + ": switching to day law"); } } }; attitudesSequence.addSwitchingCondition(dayObservationLaw, nightRestingLaw, dayNightEvent, false, true, 10.0, AngularDerivativesFilter.USE_R, switchHandler); attitudesSequence.addSwitchingCondition(nightRestingLaw, dayObservationLaw, nightDayEvent, true, false, 10.0, AngularDerivativesFilter.USE_R, switchHandler); if (dayNightEvent.g(new SpacecraftState(initialOrbit)) >= 0) { // initial position is in daytime attitudesSequence.resetActiveProvider(dayObservationLaw); } else { // initial position is in nighttime attitudesSequence.resetActiveProvider(nightRestingLaw); } // Propagator : consider the analytical Eckstein-Hechler model final Propagator propagator = new EcksteinHechlerPropagator(initialOrbit, attitudesSequence, Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS, Constants.EIGEN5C_EARTH_MU, Constants.EIGEN5C_EARTH_C20, Constants.EIGEN5C_EARTH_C30, Constants.EIGEN5C_EARTH_C40, Constants.EIGEN5C_EARTH_C50, Constants.EIGEN5C_EARTH_C60); // Register the switching events to the propagator attitudesSequence.registerSwitchEvents(propagator); propagator.setMasterMode(180.0, new OrekitFixedStepHandler() { public void init(final SpacecraftState s0, final AbsoluteDate t) { } public void handleStep(SpacecraftState currentState, boolean isLast) throws PropagationException { try { DecimalFormatSymbols angleDegree = new DecimalFormatSymbols(Locale.US); angleDegree.setDecimalSeparator('\u00b0'); DecimalFormat ad = new DecimalFormat(" 00.000;-00.000", angleDegree); // the Earth position in spacecraft frame should be along spacecraft Z axis // during nigthtime and away from it during daytime due to roll and pitch offsets final Vector3D earth = currentState.toTransform().transformPosition(Vector3D.ZERO); final double pointingOffset = Vector3D.angle(earth, Vector3D.PLUS_K); // the g function is the eclipse indicator, its an angle between Sun and Earth limb, // positive when Sun is outside of Earth limb, negative when Sun is hidden by Earth limb final double eclipseAngle = dayNightEvent.g(currentState); output.add(currentState.getDate() + " " + ad.format(FastMath.toDegrees(eclipseAngle)) + " " + ad.format(FastMath.toDegrees(pointingOffset))); } catch (OrekitException oe) { throw new PropagationException(oe); } } }); // Propagate from the initial date for the fixed duration SpacecraftState finalState = propagator.propagate(initialDate.shiftedBy(12600.)); // we print the lines according to lexicographic order, which is chronological order here // to make sure out of orders calls between step handler and event handlers don't mess things up for (final String line : output) { System.out.println(line); } System.out.println("Propagation ended at " + finalState.getDate()); } catch (OrekitException oe) { System.err.println(oe.getMessage()); } }
From source file:com.tussle.main.Utility.java
public static double[] getXYfromDM(double direction, double magnitude) { double[] returnVect = new double[2]; returnVect[0] = magnitude * FastMath.cos(FastMath.toRadians(direction)); returnVect[1] = magnitude * FastMath.sin(FastMath.toDegrees(direction)); return returnVect; }
From source file:com.tussle.main.Utility.java
public static double angle(double x, double y) { return FastMath.toDegrees(FastMath.atan2(y, x)); }
From source file:com.tussle.collision.CollisionCorner.java
public void draw(ShapeRenderer drawer) { double minAngle = FastMath.toDegrees(FastMath.atan2(minVec.yNorm(), minVec.xNorm())); double maxAngle = FastMath.toDegrees(FastMath.atan2(maxVec.yNorm(), maxVec.xNorm())); drawer.arc((float) x, (float) y, 12, (float) minAngle, (float) (maxAngle - minAngle)); drawer.line((float) x, (float) y, (float) (x + minVec.xNorm() * 20), (float) (y + minVec.yNorm() * 20)); drawer.line((float) x, (float) y, (float) (x + maxVec.xNorm() * 20), (float) (y + maxVec.yNorm() * 20)); }
From source file:edu.mit.fss.examples.member.OrekitSurfaceElement.java
/** * Gets the azimuth (in degrees) to the specified element. * * @param element the element//from www. j av a 2 s . c o m * @return the azimuth to */ public double getAzimuth(Element element) { if (element.getFrame() == ReferenceFrame.UNKNOWN) { logger.warn("Unknown reference frame for element " + element + ", cannot compute azimuth."); return 0; } try { // use topocentric frame to compute azimuth return FastMath.toDegrees( topoFrame.getAzimuth(element.getPosition(), element.getFrame().getOrekitFrame(), getDate())); } catch (OrekitException e) { logger.error(e.getMessage()); } return 0; }
From source file:fr.cs.examples.propagation.VisibilityCircle.java
private void run(final File input, final File output, final String separator) throws IOException, IllegalArgumentException, OrekitException { // read input parameters KeyValueFileParser<ParameterKey> parser = new KeyValueFileParser<ParameterKey>(ParameterKey.class); parser.parseInput(new FileInputStream(input)); double minElevation = parser.getAngle(ParameterKey.MIN_ELEVATION); double radius = Constants.WGS84_EARTH_EQUATORIAL_RADIUS + parser.getDouble(ParameterKey.SPACECRAFT_ALTITUDE); int points = parser.getInt(ParameterKey.POINTS_NUMBER); // station properties double latitude = parser.getAngle(ParameterKey.STATION_LATITUDE); double longitude = parser.getAngle(ParameterKey.STATION_LONGITUDE); double altitude = parser.getDouble(ParameterKey.STATION_ALTITUDE); String name = parser.getString(ParameterKey.STATION_NAME); // compute visibility circle List<GeodeticPoint> circle = computeCircle(latitude, longitude, altitude, name, minElevation, radius, points);// w w w . ja v a 2 s .c om // create a 2 columns csv file representing the visibility circle // in the user home directory, with latitude in column 1 and longitude in column 2 DecimalFormat format = new DecimalFormat("#00.00000", new DecimalFormatSymbols(Locale.US)); PrintStream csvFile = new PrintStream(output); for (GeodeticPoint p : circle) { csvFile.println(format.format(FastMath.toDegrees(p.getLatitude())) + "," + format.format(FastMath.toDegrees(p.getLongitude()))); } csvFile.close(); }
From source file:edu.mit.fss.examples.member.OrekitSurfaceElement.java
/** * Gets the elevation (in degrees) to the specified element. * * @param element the element//from w w w. j a v a 2 s. c o m * @return the elevation to */ public double getElevation(Element element) { if (element.getFrame() == ReferenceFrame.UNKNOWN) { logger.warn("Unknown reference frame for element " + element + ", cannot compute elevation."); return 0; } try { // use topocentric frame to compute elevation angle return FastMath.toDegrees( topoFrame.getElevation(element.getPosition(), element.getFrame().getOrekitFrame(), getDate())); } catch (OrekitException e) { logger.error(e.getMessage()); } return 0; }
From source file:edu.mit.fss.examples.member.OrekitOrbitalElement.java
@Override public double getArgumentOfPeriapsis() { // convert spacecraft state to Keplerian orbit return FastMath.toDegrees(new KeplerianOrbit(state.getOrbit()).getPerigeeArgument()); }