Search in sources :

Example 11 with MathRuntimeException

use of org.hipparchus.exception.MathRuntimeException in project Orekit by CS-SI.

the class SecularAndHarmonicTest method findLatitudeCrossing.

private SpacecraftState findLatitudeCrossing(final double latitude, final AbsoluteDate guessDate, final AbsoluteDate endDate, final double shift, final double maxShift, final Propagator propagator) throws OrekitException, MathRuntimeException {
    // function evaluating to 0 at latitude crossings
    final UnivariateFunction latitudeFunction = new UnivariateFunction() {

        /**
         * {@inheritDoc}
         */
        public double value(double x) {
            try {
                final SpacecraftState state = propagator.propagate(guessDate.shiftedBy(x));
                final Vector3D position = state.getPVCoordinates(earth.getBodyFrame()).getPosition();
                final GeodeticPoint point = earth.transform(position, earth.getBodyFrame(), state.getDate());
                return point.getLatitude() - latitude;
            } catch (OrekitException oe) {
                throw new RuntimeException(oe);
            }
        }
    };
    // try to bracket the encounter
    double span;
    if (guessDate.shiftedBy(shift).compareTo(endDate) > 0) {
        // Take a 1e-3 security margin
        span = endDate.durationFrom(guessDate) - 1e-3;
    } else {
        span = shift;
    }
    while (!UnivariateSolverUtils.isBracketing(latitudeFunction, -span, span)) {
        if (2 * span > maxShift) {
            // let the Hipparchus exception be thrown
            UnivariateSolverUtils.verifyBracketing(latitudeFunction, -span, span);
        } else if (guessDate.shiftedBy(2 * span).compareTo(endDate) > 0) {
            // Out of range :
            return null;
        }
        // expand the search interval
        span *= 2;
    }
    // find the encounter in the bracketed interval
    final BaseUnivariateSolver<UnivariateFunction> solver = new BracketingNthOrderBrentSolver(0.1, 5);
    final double dt = solver.solve(1000, latitudeFunction, -span, span);
    return propagator.propagate(guessDate.shiftedBy(dt));
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) MathRuntimeException(org.hipparchus.exception.MathRuntimeException) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) BracketingNthOrderBrentSolver(org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver)

Aggregations

MathRuntimeException (org.hipparchus.exception.MathRuntimeException)11 OrekitException (org.orekit.errors.OrekitException)8 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)5 BracketingNthOrderBrentSolver (org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver)5 GeodeticPoint (org.orekit.bodies.GeodeticPoint)5 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)4 OrekitExceptionWrapper (org.orekit.errors.OrekitExceptionWrapper)4 SpacecraftState (org.orekit.propagation.SpacecraftState)4 UnivariateSolver (org.hipparchus.analysis.solvers.UnivariateSolver)3 RealFieldUnivariateFunction (org.hipparchus.analysis.RealFieldUnivariateFunction)2 FieldBracketingNthOrderBrentSolver (org.hipparchus.analysis.solvers.FieldBracketingNthOrderBrentSolver)2 FieldLine (org.hipparchus.geometry.euclidean.threed.FieldLine)2 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)2 Line (org.hipparchus.geometry.euclidean.threed.Line)2 Test (org.junit.Test)2 FieldGeodeticPoint (org.orekit.bodies.FieldGeodeticPoint)2 FieldTransform (org.orekit.frames.FieldTransform)2 Frame (org.orekit.frames.Frame)2 Transform (org.orekit.frames.Transform)2 AbsoluteDate (org.orekit.time.AbsoluteDate)2