Example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D.

Prototype

public Vector3D(double x, double y, double z) 

Source Link

Document

Simple constructor.

Usage

From source file:lambertmrev.LambertMRev.java

/**
 * @param args the command line arguments
 *///from  w w w .  j av a  2 s. com
public static void main(String[] args) {
    // Want to test the Lambert class so you can specify the number of revs for which to compute
    //System.out.print("this is the frames tutorial \n");
    try {
        Frame inertialFrame = FramesFactory.getEME2000();
        TimeScale utc = TimeScalesFactory.getTAI();
        AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, utc);
        double mu = 3.986004415e+14;

        double a = 24396159; // semi major axis in meters
        double e = 0.72831215; // eccentricity
        double i = Math.toRadians(7); // inclination
        double omega = Math.toRadians(180); // perigee argument
        double raan = Math.toRadians(261); // right ascension of ascending node
        double lM = 0; // mean anomaly

        Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame,
                initialDate, mu);
        //KeplerianPropagator kepler = new KeplerianPropagator(initialOrbit);

        // set geocentric positions
        Vector3D r1 = new Vector3D(-6.88999e3, 3.92763e4, 2.67053e3);
        Vector3D r2 = new Vector3D(-3.41458e4, 2.05328e4, 3.44315e3);
        Vector3D r1_site = new Vector3D(4.72599e3, 1.26633e3, 4.07799e3);
        Vector3D r2_site = new Vector3D(4.70819e3, 1.33099e3, 4.07799e3);

        // get the topocentric positions
        Vector3D top1 = Transform.geo2radec(r1.scalarMultiply(1000), r1_site.scalarMultiply(1000));
        Vector3D top2 = Transform.geo2radec(r2.scalarMultiply(1000), r2_site.scalarMultiply(1000));

        // time of flight in seconds
        double tof = 3 * 3600;

        // propagate to 0 and tof
        Lambert test = new Lambert();

        boolean cw = false;
        int multi_revs = 1;
        RealMatrix v1_mat;
        Random randomGenerator = new Random();

        PrintWriter out_a = new PrintWriter("out_java_a.txt");
        PrintWriter out_e = new PrintWriter("out_java_e.txt");
        PrintWriter out_rho1 = new PrintWriter("out_java_rho1.txt");
        PrintWriter out_rho2 = new PrintWriter("out_java_rho2.txt");

        // start the loop
        double A, Ecc, rho1, rho2, tof_hyp;

        long time1 = System.nanoTime();
        for (int ll = 0; ll < 1e6; ll++) {

            rho1 = top1.getZ() / 1000 + 1e-3 * randomGenerator.nextGaussian() * top1.getZ() / 1000;
            rho2 = top2.getZ() / 1000 + 1e-3 * randomGenerator.nextGaussian() * top2.getZ() / 1000;
            //tof_hyp = FastMath.abs(tof + 0.1*3600 * randomGenerator.nextGaussian());
            // from topo to geo
            Vector3D r1_hyp = Transform.radec2geo(top1.getX(), top1.getY(), rho1, r1_site);
            Vector3D r2_hyp = Transform.radec2geo(top2.getX(), top2.getY(), rho2, r2_site);
            //            System.out.println(r1_hyp.scalarMultiply(1000).getNorm());
            //            System.out.println(r2_hyp.scalarMultiply(1000).getNorm());
            //            System.out.println(tof/3600);
            test.lambert_problem(r1_hyp.scalarMultiply(1000), r2_hyp.scalarMultiply(1000), tof, mu, cw,
                    multi_revs);

            v1_mat = test.get_v1();

            Vector3D v1 = new Vector3D(v1_mat.getEntry(0, 0), v1_mat.getEntry(0, 1), v1_mat.getEntry(0, 2));
            //            System.out.println(v1);
            PVCoordinates rv1 = new PVCoordinates(r1_hyp.scalarMultiply(1000), v1);
            Orbit orbit_out = new KeplerianOrbit(rv1, inertialFrame, initialDate, mu);
            A = orbit_out.getA();
            Ecc = orbit_out.getE();

            //            System.out.println(ll + " - " +A);
            out_a.println(A);
            out_e.println(Ecc);
            out_rho1.println(rho1);
            out_rho2.println(rho2);
        }
        long time2 = System.nanoTime();
        long timeTaken = time2 - time1;

        out_a.close();
        out_e.close();
        out_rho1.close();
        out_rho2.close();

        System.out.println("Time taken " + timeTaken / 1000 / 1000 + " milli secs");

        // get the truth
        test.lambert_problem(r1.scalarMultiply(1000), r2.scalarMultiply(1000), tof, mu, cw, multi_revs);
        v1_mat = test.get_v1();
        Vector3D v1 = new Vector3D(v1_mat.getEntry(0, 0), v1_mat.getEntry(0, 1), v1_mat.getEntry(0, 2));
        PVCoordinates rv1 = new PVCoordinates(r1.scalarMultiply(1000), v1);
        Orbit orbit_out = new KeplerianOrbit(rv1, inertialFrame, initialDate, mu);
        //System.out.println(orbit_out.getA());
    } catch (FileNotFoundException ex) {
        Logger.getLogger(LambertMRev.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:fr.cs.examples.frames.Frames1.java

public static void main(String[] args) {
    try {/*  w  ww. j  a  v a 2s.  c  o m*/

        // configure Orekit
        Autoconfiguration.configureOrekit();

        //  Initial state definition : date, orbit
        TimeScale utc = TimeScalesFactory.getUTC();
        AbsoluteDate initialDate = new AbsoluteDate(2008, 10, 01, 0, 0, 00.000, utc);
        double mu = 3.986004415e+14; // gravitation coefficient
        Frame inertialFrame = FramesFactory.getEME2000(); // inertial frame for orbit definition
        Vector3D posisat = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
        Vector3D velosat = new Vector3D(505.8479685, 942.7809215, 7435.922231);
        PVCoordinates pvsat = new PVCoordinates(posisat, velosat);
        Orbit initialOrbit = new CartesianOrbit(pvsat, inertialFrame, initialDate, mu);

        // Propagator : consider a simple keplerian motion
        Propagator kepler = new KeplerianPropagator(initialOrbit);

        // The local orbital frame (LOF) is related to the orbit propagated by the kepler propagator.
        LocalOrbitalFrame lof = new LocalOrbitalFrame(inertialFrame, LOFType.QSW, kepler, "QSW");

        // Earth and frame
        Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
                Constants.WGS84_EARTH_FLATTENING, earthFrame);

        // Station
        final double longitude = FastMath.toRadians(45.);
        final double latitude = FastMath.toRadians(25.);
        final double altitude = 0.;
        final GeodeticPoint station = new GeodeticPoint(latitude, longitude, altitude);
        final TopocentricFrame staF = new TopocentricFrame(earth, station, "station");

        System.out.println("          time           doppler (m/s)");

        // Stop date
        final AbsoluteDate finalDate = new AbsoluteDate(initialDate, 6000, utc);

        // Loop
        AbsoluteDate extrapDate = initialDate;
        while (extrapDate.compareTo(finalDate) <= 0) {

            // We can simply get the position and velocity of station in LOF frame at any time
            PVCoordinates pv = staF.getTransformTo(lof, extrapDate).transformPVCoordinates(PVCoordinates.ZERO);

            // And then calculate the doppler signal
            double doppler = Vector3D.dotProduct(pv.getPosition(), pv.getVelocity())
                    / pv.getPosition().getNorm();

            System.out.format(Locale.US, "%s   %9.3f%n", extrapDate, doppler);

            extrapDate = new AbsoluteDate(extrapDate, 600, utc);

        }

    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}

From source file:fr.cs.examples.propagation.VisibilityCheck.java

/** Program entry point.
 * @param args program arguments (unused here)
 *///ww w. j  a v  a 2s.  c o  m
public static void main(String[] args) {
    try {

        // configure Orekit
        Autoconfiguration.configureOrekit();

        //  Initial state definition : date, orbit
        AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC());
        double mu = 3.986004415e+14; // gravitation coefficient
        Frame inertialFrame = FramesFactory.getEME2000(); // inertial frame for orbit definition
        Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
        Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231);
        PVCoordinates pvCoordinates = new PVCoordinates(position, velocity);
        Orbit initialOrbit = new KeplerianOrbit(pvCoordinates, inertialFrame, initialDate, mu);

        // Propagator : consider a simple keplerian motion (could be more elaborate)
        Propagator kepler = new KeplerianPropagator(initialOrbit);

        // Earth and frame
        Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
        BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
                Constants.WGS84_EARTH_FLATTENING, earthFrame);

        // Station
        final double longitude = FastMath.toRadians(45.);
        final double latitude = FastMath.toRadians(25.);
        final double altitude = 0.;
        final GeodeticPoint station1 = new GeodeticPoint(latitude, longitude, altitude);
        final TopocentricFrame sta1Frame = new TopocentricFrame(earth, station1, "station1");

        // Event definition
        final double maxcheck = 60.0;
        final double threshold = 0.001;
        final double elevation = FastMath.toRadians(5.0);
        final EventDetector sta1Visi = new ElevationDetector(maxcheck, threshold, sta1Frame)
                .withConstantElevation(elevation).withHandler(new VisibilityHandler());

        // Add event to be detected
        kepler.addEventDetector(sta1Visi);

        // Propagate from the initial date to the first raising or for the fixed duration
        SpacecraftState finalState = kepler.propagate(initialDate.shiftedBy(1500.));

        System.out.println(" Final state : " + finalState.getDate().durationFrom(initialDate));

    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}

From source file:fr.cs.examples.frames.Frames2.java

public static void main(String[] args) {
    try {//from w  w  w.  j av a  2s.com

        // configure Orekit
        Autoconfiguration.configureOrekit();

        // Considering the following Computing/Measurement date in UTC time scale
        TimeScale utc = TimeScalesFactory.getUTC();
        AbsoluteDate date = new AbsoluteDate(2008, 10, 01, 12, 00, 00.000, utc);

        // The Center of Gravity frame has its origin at the satellite center of gravity (CoG)
        // and its axes parallel to EME2000. It is derived from EME2000 frame at any moment
        // by an unknown transform which depends on the current position and the velocity.
        // Let's initialize this transform by the identity transform.
        UpdatableFrame cogFrame = new UpdatableFrame(FramesFactory.getEME2000(), Transform.IDENTITY, "LOF",
                false);

        // The satellite frame, with origin also at the CoG, depends on attitude.
        // For the sake of this tutorial, we consider a simple inertial attitude here
        Transform cogToSat = new Transform(date, new Rotation(0.6, 0.48, 0, 0.64, false));
        Frame satFrame = new Frame(cogFrame, cogToSat, "sat", false);

        // Finally, the GPS antenna frame can be defined from the satellite frame by 2 transforms:
        // a translation and a rotation
        Transform translateGPS = new Transform(date, new Vector3D(0, 0, 1));
        Transform rotateGPS = new Transform(date, new Rotation(new Vector3D(0, 1, 3), FastMath.toRadians(10)));
        Frame gpsFrame = new Frame(satFrame, new Transform(date, translateGPS, rotateGPS), "GPS", false);

        // Let's get the satellite position and velocity in ITRF as measured by GPS antenna at this moment:
        final Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
        final Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231);
        System.out.format(Locale.US, "GPS antenna position in ITRF:    %12.3f %12.3f %12.3f%n", position.getX(),
                position.getY(), position.getZ());
        System.out.format(Locale.US, "GPS antenna velocity in ITRF:    %12.7f %12.7f %12.7f%n", velocity.getX(),
                velocity.getY(), velocity.getZ());

        // The transform from GPS frame to ITRF frame at this moment is defined by
        // a translation and a rotation. The translation is directly provided by the
        // GPS measurement above. The rotation is extracted from the existing tree, where
        // we know all rotations are already up to date, even if one translation is still
        // unknown. We combine the extracted rotation and the measured translation by
        // applying the rotation first because the position/velocity vector are given in
        // ITRF frame not in GPS antenna frame:
        Transform measuredTranslation = new Transform(date, position, velocity);
        Transform formerTransform = gpsFrame
                .getTransformTo(FramesFactory.getITRF(IERSConventions.IERS_2010, true), date);
        Transform preservedRotation = new Transform(date, formerTransform.getRotation(),
                formerTransform.getRotationRate());
        Transform gpsToItrf = new Transform(date, preservedRotation, measuredTranslation);

        // So we can update the transform from EME2000 to CoG frame
        cogFrame.updateTransform(gpsFrame, FramesFactory.getITRF(IERSConventions.IERS_2010, true), gpsToItrf,
                date);

        // And we can get the position and velocity of satellite CoG in EME2000 frame
        PVCoordinates origin = PVCoordinates.ZERO;
        Transform cogToItrf = cogFrame.getTransformTo(FramesFactory.getITRF(IERSConventions.IERS_2010, true),
                date);
        PVCoordinates satItrf = cogToItrf.transformPVCoordinates(origin);
        System.out.format(Locale.US, "Satellite   position in ITRF:    %12.3f %12.3f %12.3f%n",
                satItrf.getPosition().getX(), satItrf.getPosition().getY(), satItrf.getPosition().getZ());
        System.out.format(Locale.US, "Satellite   velocity in ITRF:    %12.7f %12.7f %12.7f%n",
                satItrf.getVelocity().getX(), satItrf.getVelocity().getY(), satItrf.getVelocity().getZ());

        Transform cogToEme2000 = cogFrame.getTransformTo(FramesFactory.getEME2000(), date);
        PVCoordinates satEME2000 = cogToEme2000.transformPVCoordinates(origin);
        System.out.format(Locale.US, "Satellite   position in EME2000: %12.3f %12.3f %12.3f%n",
                satEME2000.getPosition().getX(), satEME2000.getPosition().getY(),
                satEME2000.getPosition().getZ());
        System.out.format(Locale.US, "Satellite   velocity in EME2000: %12.7f %12.7f %12.7f%n",
                satEME2000.getVelocity().getX(), satEME2000.getVelocity().getY(),
                satEME2000.getVelocity().getZ());

    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}

From source file:fr.cs.examples.attitude.EarthObservation.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();
        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:edu.mit.fss.tutorial.part2.OfflineTutorialFederate.java

/**
 * The main method./* w  w  w . j  a v  a2  s . c om*/
 *
 * @param args the arguments
 * @throws RTIexception the RTI exception
 */
public static void main(String[] args) throws RTIexception {
    // Configure the logger and set it to display info messages.
    BasicConfigurator.configure();
    logger.setLevel(Level.INFO);

    // Create a MobileElement object instance.
    MobileElement element = new MobileElement("Element", new Vector3D(10, 0, 0));

    // Create a OfflineTutorialFederate object instance.
    OfflineTutorialFederate fed = new OfflineTutorialFederate(element);

    // Execute the federate and exit when complete.
    fed.execute(0, 20000, 1000);
    fed.exit();
}

From source file:fr.cs.examples.attitude.EarthObservation_day_night_switch_with_fixed_transitions.java

/** Program entry point.
 * @param args program arguments (unused here)
 *//*from  w  ww .j a  v  a  2s  .  c  om*/
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, 02, 00, 00, 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 AttitudesSequence attitudesSequence = new AttitudesSequence();

        // Attitude laws definition
        //-------------------------

        // Mode : day
        final AttitudeProvider dayObservationLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH,
                RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(40), 0);

        // Mode : night
        final AttitudeProvider nightRestingLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH);

        // Mode : day-night rdv 1
        final AttitudeProvider dayNightRdV1Law = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH,
                RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(20), 0);

        // Mode : day-night rdv 2
        final AttitudeProvider dayNightRdV2Law = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH,
                RotationOrder.XYZ, FastMath.toRadians(20), 0, 0);

        // Mode : night-day rdv 1
        final AttitudeProvider nightDayRdV1Law = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH,
                RotationOrder.XYZ, FastMath.toRadians(20), 0, 0);

        // Mode : night-day rdv 2
        final AttitudeProvider nightDayRdV2Law = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH,
                RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(20), 0);

        // Event detectors definition
        //---------------------------
        final PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
        final PVCoordinatesProvider earth = CelestialBodyFactory.getEarth();

        // Detectors : end day-night rdv 2
        final DateDetector endDayNightRdV2Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-day-night-2 night-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endDayNightRdV2Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to night law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-day-night-2 night-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end day-night rdv 1
        final DateDetector endDayNightRdV1Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-day-night-1 day-night-rdv2-mode");
                            endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endDayNightRdV1Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-day-night-1 day-night-rdv2-mode");
                            endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detector : eclipse entry
        final EventDetector dayNightEvent = new EclipseDetector(sun, 696000000., earth,
                Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 1 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " eclipse-entry day-night-rdv1-mode");
                            endDayNightRdV1Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endDayNightRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end night-day rdv 2
        final DateDetector endNightDayRdV2Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to day law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-night-day-2 day-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endNightDayRdV2Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-night-day-2 day-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end night-day rdv 1
        final DateDetector endNightDayRdV1Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-night-day-1 night-day-rdv2-mode");
                            endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endNightDayRdV1Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-night-day-1 night-day-rdv2-mode");
                            endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detector : eclipse exit
        final EventDetector nightDayEvent = new EclipseDetector(sun, 696000000., earth,
                Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 1 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " eclipse-exit night-day-rdv1-mode");
                            endNightDayRdV1Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endNightDayRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Attitude sequences definition
        //------------------------------
        attitudesSequence.addSwitchingCondition(dayObservationLaw, dayNightEvent, false, true, dayNightRdV1Law);
        attitudesSequence.addSwitchingCondition(dayNightRdV1Law, endDayNightRdV1Event_increase, true, false,
                dayNightRdV2Law);
        attitudesSequence.addSwitchingCondition(dayNightRdV1Law, endDayNightRdV1Event_decrease, false, true,
                dayNightRdV2Law);
        attitudesSequence.addSwitchingCondition(dayNightRdV2Law, endDayNightRdV2Event_increase, true, false,
                nightRestingLaw);
        attitudesSequence.addSwitchingCondition(dayNightRdV2Law, endDayNightRdV2Event_decrease, false, true,
                nightRestingLaw);
        attitudesSequence.addSwitchingCondition(nightRestingLaw, nightDayEvent, true, false, nightDayRdV1Law);
        attitudesSequence.addSwitchingCondition(nightDayRdV1Law, endNightDayRdV1Event_increase, true, false,
                nightDayRdV2Law);
        attitudesSequence.addSwitchingCondition(nightDayRdV1Law, endNightDayRdV1Event_decrease, false, true,
                nightDayRdV2Law);
        attitudesSequence.addSwitchingCondition(nightDayRdV2Law, endNightDayRdV2Event_increase, true, false,
                dayObservationLaw);
        attitudesSequence.addSwitchingCondition(nightDayRdV2Law, endNightDayRdV2Event_decrease, false, true,
                dayObservationLaw);

        // Initialisation
        //---------------
        if (dayNightEvent.g(new SpacecraftState(initialOrbit)) >= 0) {
            // initial position is in daytime
            attitudesSequence.resetActiveProvider(dayObservationLaw);
            System.out
                    .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY)
                            + " begin with day law");
        } else {
            // initial position is in nighttime
            attitudesSequence.resetActiveProvider(nightRestingLaw);
            System.out
                    .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY)
                            + " begin with night law");
        }

        //----------------------
        // Propagator definition
        //----------------------

        // 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(10.0, new OrekitFixedStepHandler() {
            private DecimalFormat f1 = new DecimalFormat("0.0000000000000000E00",
                    new DecimalFormatSymbols(Locale.US));
            private Vector3DFormat f2 = new Vector3DFormat(" ", " ", " ", f1);
            private PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
            private PVCoordinatesProvider moon = CelestialBodyFactory.getMoon();
            private Frame eme2000 = FramesFactory.getEME2000();
            private Frame itrf2005 = FramesFactory.getITRF(IERSConventions.IERS_2010, true);

            private String printVector3D(final String name, final Vector3D v) {
                return name + " " + f2.format(v);
            }

            private String printRotation(final String name, final Rotation r) {
                return name + " " + f1.format(r.getQ1()) + " " + f1.format(r.getQ2()) + " "
                        + f1.format(r.getQ3()) + " " + f1.format(r.getQ0());
            }

            private String printRotation2(final String name, final Rotation r) {
                return name + " " + f1.format(-r.getQ1()) + " " + f1.format(-r.getQ2()) + " "
                        + f1.format(-r.getQ3()) + " " + f1.format(-r.getQ0());
            }

            public void init(final SpacecraftState s0, final AbsoluteDate t) {
            }

            public void handleStep(SpacecraftState currentState, boolean isLast) throws PropagationException {
                try {
                    // the Earth position in spacecraft 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);

                    final double endNightDayTimer1 = endNightDayRdV1Event_decrease.g(currentState);
                    final double endNightDayTimer2 = endNightDayRdV2Event_decrease.g(currentState);
                    final double endDayNightTimer1 = endDayNightRdV1Event_decrease.g(currentState);
                    final double endDayNightTimer2 = endDayNightRdV2Event_decrease.g(currentState);

                    output.add(currentState.getDate() + " " + FastMath.toDegrees(eclipseAngle) + " "
                            + endNightDayTimer1 + " " + endNightDayTimer2 + " " + endDayNightTimer1 + " "
                            + endDayNightTimer2 + " " + FastMath.toDegrees(pointingOffset));
                    final AbsoluteDate date = currentState.getDate();
                    final PVCoordinates pv = currentState.getPVCoordinates(eme2000);
                    final Rotation lvlhRot = new Rotation(pv.getPosition(), pv.getMomentum(), Vector3D.MINUS_K,
                            Vector3D.MINUS_J);
                    final Rotation earthRot = eme2000.getTransformTo(itrf2005, date).getRotation();
                    System.out.println("Scenario::setVectorMap 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " "
                            + printVector3D("sun", sun.getPVCoordinates(date, eme2000).getPosition()) + " "
                            + printVector3D("moon", moon.getPVCoordinates(date, eme2000).getPosition()) + " "
                            + printVector3D("satPos", pv.getPosition()) + " "
                            + printVector3D("satVel", pv.getVelocity()) + " "
                            + printVector3D("orbMom", pv.getMomentum()));
                    System.out.println("Scenario::setQuatMap 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " "
                            + printRotation("earthFrame", earthRot) + " "
                            + printRotation("LVLHFrame", lvlhRot));
                    System.out.println("Scenario::computeStep 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY));
                    System.out.println("  -> " + printRotation2("", currentState.getAttitude().getRotation())
                            + " " + printVector3D("", currentState.getAttitude().getSpin()));
                } catch (OrekitException oe) {
                    throw new PropagationException(oe);
                }
            }
        });

        //----------
        // Propagate
        //----------

        // Propagate from the initial date for the fixed duration
        propagator.propagate(initialDate.shiftedBy(1.75 * 3600.));

        //--------------
        // Print results
        //--------------

        // 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);
        }

    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}

From source file:fr.cs.examples.attitude.EarthObservation_day_night_switch_with_spinned_transitions.java

/** Program entry point.
 * @param args program arguments (unused here)
 *//* w w w.  j  a  v  a 2 s  .c  om*/
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, 02, 00, 00, 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 AttitudesSequence attitudesSequence = new AttitudesSequence();

        // Attitude laws definition
        final double settingRate = FastMath.toRadians(1.0);
        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 AttitudeProvider transitionLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH,
                RotationOrder.XYZ, FastMath.toRadians(20), 0, 0);
        final AttitudeProvider rollSetUpLaw = new SpinStabilized(nightRestingLaw, AbsoluteDate.J2000_EPOCH,
                Vector3D.PLUS_I, settingRate);
        final AttitudeProvider pitchSetUpLaw = new SpinStabilized(transitionLaw, AbsoluteDate.J2000_EPOCH,
                Vector3D.PLUS_J, settingRate);
        final AttitudeProvider pitchTearDownLaw = new SpinStabilized(dayObservationLaw,
                AbsoluteDate.J2000_EPOCH, Vector3D.PLUS_J, -settingRate);
        final AttitudeProvider rollTearDownLaw = new SpinStabilized(transitionLaw, AbsoluteDate.J2000_EPOCH,
                Vector3D.PLUS_I, -settingRate);

        // Event detectors definition
        //---------------------------
        final PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
        final PVCoordinatesProvider earth = CelestialBodyFactory.getEarth();

        // Detectors : end day-night rdv 2
        final DateDetector endDayNightRdV2Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-day-night-2 night-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endDayNightRdV2Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to night law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-day-night-2 night-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end day-night rdv 1
        final DateDetector endDayNightRdV1Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-day-night-1 day-night-rdv2-mode");
                            endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endDayNightRdV1Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-day-night-1 day-night-rdv2-mode");
                            endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detector : eclipse entry
        final EventDetector dayNightEvent = new EclipseDetector(sun, 696000000., earth,
                Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day-night rdv 1 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " eclipse-entry day-night-rdv1-mode");
                            endDayNightRdV1Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endDayNightRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end night-day rdv 2
        final DateDetector endNightDayRdV2Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to day law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-night-day-2 day-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endNightDayRdV2Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to day law");
                            System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                    / Constants.JULIAN_DAY) + " end-night-day-2 day-mode");
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detectors : end night-day rdv 1
        final DateDetector endNightDayRdV1Event_increase = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-night-day-1 night-day-rdv2-mode");
                            endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        final DateDetector endNightDayRdV1Event_decrease = new DateDetector(10, 1e-04)
                .withHandler(new EventHandler<DateDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final DateDetector detector,
                            final boolean increasing) {
                        if (!increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 2 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " end-night-day-1 night-day-rdv2-mode");
                            endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40));
                            endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Detector : eclipse exit
        final EventDetector nightDayEvent = new EclipseDetector(sun, 696000000., earth,
                Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() {
                    public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector,
                            final boolean increasing) {
                        if (increasing) {
                            output.add(s.getDate() + ": switching to night-day rdv 1 law");
                            System.out
                                    .println("# "
                                            + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH)
                                                    / Constants.JULIAN_DAY)
                                            + " eclipse-exit night-day-rdv1-mode");
                            endNightDayRdV1Event_increase.addEventDate(s.getDate().shiftedBy(20));
                            endNightDayRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(20));
                        }
                        return Action.CONTINUE;
                    }

                    public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) {
                        return oldState;
                    }
                });

        // Attitude sequences definition
        //------------------------------
        attitudesSequence.addSwitchingCondition(dayObservationLaw, dayNightEvent, false, true,
                pitchTearDownLaw);
        attitudesSequence.addSwitchingCondition(pitchTearDownLaw, endDayNightRdV1Event_increase, true, false,
                rollTearDownLaw);
        attitudesSequence.addSwitchingCondition(pitchTearDownLaw, endDayNightRdV1Event_decrease, false, true,
                rollTearDownLaw);
        attitudesSequence.addSwitchingCondition(rollTearDownLaw, endDayNightRdV2Event_increase, true, false,
                nightRestingLaw);
        attitudesSequence.addSwitchingCondition(rollTearDownLaw, endDayNightRdV2Event_decrease, false, true,
                nightRestingLaw);
        attitudesSequence.addSwitchingCondition(nightRestingLaw, nightDayEvent, true, false, rollSetUpLaw);
        attitudesSequence.addSwitchingCondition(rollSetUpLaw, endNightDayRdV1Event_increase, true, false,
                pitchSetUpLaw);
        attitudesSequence.addSwitchingCondition(rollSetUpLaw, endNightDayRdV1Event_decrease, false, true,
                pitchSetUpLaw);
        attitudesSequence.addSwitchingCondition(pitchSetUpLaw, endNightDayRdV2Event_increase, true, false,
                dayObservationLaw);
        attitudesSequence.addSwitchingCondition(pitchSetUpLaw, endNightDayRdV2Event_decrease, false, true,
                dayObservationLaw);

        // Initialisation
        //---------------
        if (dayNightEvent.g(new SpacecraftState(initialOrbit)) >= 0) {
            // initial position is in daytime
            attitudesSequence.resetActiveProvider(dayObservationLaw);
            System.out
                    .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY)
                            + " begin with day law");
        } else {
            // initial position is in nighttime
            attitudesSequence.resetActiveProvider(nightRestingLaw);
            System.out
                    .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY)
                            + " begin with night law");
        }

        //----------------------
        // Propagator definition
        //----------------------

        // 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(10.0, new OrekitFixedStepHandler() {
            private DecimalFormat f1 = new DecimalFormat("0.0000000000000000E00",
                    new DecimalFormatSymbols(Locale.US));
            private Vector3DFormat f2 = new Vector3DFormat(" ", " ", " ", f1);
            private PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
            private PVCoordinatesProvider moon = CelestialBodyFactory.getMoon();
            private Frame eme2000 = FramesFactory.getEME2000();
            private Frame itrf2005 = FramesFactory.getITRF(IERSConventions.IERS_2010, true);

            private String printVector3D(final String name, final Vector3D v) {
                return name + " " + f2.format(v);
            }

            private String printRotation(final String name, final Rotation r) {
                return name + " " + f1.format(r.getQ1()) + " " + f1.format(r.getQ2()) + " "
                        + f1.format(r.getQ3()) + " " + f1.format(r.getQ0());
            }

            private String printRotation2(final String name, final Rotation r) {
                return name + " " + f1.format(-r.getQ1()) + " " + f1.format(-r.getQ2()) + " "
                        + f1.format(-r.getQ3()) + " " + f1.format(-r.getQ0());
            }

            public void init(final SpacecraftState s0, final AbsoluteDate t) {
            }

            public void handleStep(SpacecraftState currentState, boolean isLast) throws PropagationException {
                try {
                    // the Earth position in spacecraft 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);

                    final double endNightDayTimer1 = endNightDayRdV1Event_decrease.g(currentState);
                    final double endNightDayTimer2 = endNightDayRdV2Event_decrease.g(currentState);
                    final double endDayNightTimer1 = endDayNightRdV1Event_decrease.g(currentState);
                    final double endDayNightTimer2 = endDayNightRdV2Event_decrease.g(currentState);

                    output.add(currentState.getDate() + " " + FastMath.toDegrees(eclipseAngle) + " "
                            + endNightDayTimer1 + " " + endNightDayTimer2 + " " + endDayNightTimer1 + " "
                            + endDayNightTimer2 + " " + FastMath.toDegrees(pointingOffset));
                    final AbsoluteDate date = currentState.getDate();
                    final PVCoordinates pv = currentState.getPVCoordinates(eme2000);
                    final Rotation lvlhRot = new Rotation(pv.getPosition(), pv.getMomentum(), Vector3D.MINUS_K,
                            Vector3D.MINUS_J);
                    final Rotation earthRot = eme2000.getTransformTo(itrf2005, date).getRotation();
                    System.out.println("Scenario::setVectorMap 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " "
                            + printVector3D("sun", sun.getPVCoordinates(date, eme2000).getPosition()) + " "
                            + printVector3D("moon", moon.getPVCoordinates(date, eme2000).getPosition()) + " "
                            + printVector3D("satPos", pv.getPosition()) + " "
                            + printVector3D("satVel", pv.getVelocity()) + " "
                            + printVector3D("orbMom", pv.getMomentum()));
                    System.out.println("Scenario::setQuatMap 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " "
                            + printRotation("earthFrame", earthRot) + " "
                            + printRotation("LVLHFrame", lvlhRot));
                    System.out.println("Scenario::computeStep 0x960b7e0 "
                            + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY));
                    System.out.println("  -> " + printRotation2("", currentState.getAttitude().getRotation())
                            + " " + printVector3D("", currentState.getAttitude().getSpin()));
                } catch (OrekitException oe) {
                    throw new PropagationException(oe);
                }
            }
        });

        //----------
        // Propagate
        //----------

        // Propagate from the initial date for the fixed duration
        propagator.propagate(initialDate.shiftedBy(1.75 * 3600.));

        //--------------
        // Print results
        //--------------

        // 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);
        }

    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}

From source file:Engine.AlgebraUtils.java

public static Vector3D ReturnClosestWectorMirror(double[] v1, double[] v2, WorldMap worldMap) {
    double x = (worldMap.mapSize - 1) * GenerateTerrain.Size;
    double y = (worldMap.mapSize - 1) * GenerateTerrain.Size;
    double distance = DistanceBetweenDoubleTablesMirror(v1, v2, worldMap);
    if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0], v1[1], v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0], v1[1], v1[2]);
    if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0] + x, v1[1], v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0] + x, v1[1], v1[2]);
    if (Math.abs(
            DistanceBetweenDoubleTables(new double[] { v1[0] + x, v1[1] + y, v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0] + x, v1[1] + y, v1[2]);
    if (Math.abs(
            DistanceBetweenDoubleTables(new double[] { v1[0] + x, v1[1] - y, v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0] + x, v1[1] - y, v1[2]);
    if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0] - x, v1[1], v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0] - x, v1[1], v1[2]);
    if (Math.abs(
            DistanceBetweenDoubleTables(new double[] { v1[0] - x, v1[1] + y, v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0] - x, v1[1] + y, v1[2]);
    if (Math.abs(
            DistanceBetweenDoubleTables(new double[] { v1[0] - x, v1[1] - y, v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0] - x, v1[1] - y, v1[2]);
    if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0], v1[1] + y, v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0], v1[1] + y, v1[2]);
    if (Math.abs(DistanceBetweenDoubleTables(new double[] { v1[0], v1[1] - y, v1[2] }, v2) - distance) < 0.001)
        return new Vector3D(v1[0], v1[1] - y, v1[2]);

    return Vector3D.ZERO;
}

From source file:gentracklets.conversions.java

public static double[] geo2radec(PVCoordinates obj, TopocentricFrame staF, Frame inertialFrame,
        AbsoluteDate epoch) {/* w  ww.  ja  v a 2 s . c  o  m*/

    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;
}