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