Commit de9a4c94 authored by Bryan Cazabonne's avatar Bryan Cazabonne
Browse files

Merge remote-tracking branch 'forkLouis/Issue-786' into pre-release

parents ff3ac734 b87636ac
......@@ -163,23 +163,26 @@ public abstract class Orbit
*/
protected static boolean hasNonKeplerianAcceleration(final PVCoordinates pva, final double mu) {
final Vector3D a = pva.getAcceleration();
if (a == null) {
return false;
}
final Vector3D p = pva.getPosition();
final double r2 = p.getNormSq();
final double r = FastMath.sqrt(r2);
final Vector3D keplerianAcceleration = new Vector3D(-mu / (r * r2), p);
if (a.getNorm() > 1.0e-9 * keplerianAcceleration.getNorm()) {
// Check if acceleration is null or relatively close to 0 compared to the keplerain acceleration
final Vector3D a = pva.getAcceleration();
if (a == null || a.getNorm() < 1e-9 * keplerianAcceleration.getNorm()) {
return false;
}
final Vector3D nonKeplerianAcceleration = a.subtract(keplerianAcceleration);
if ( nonKeplerianAcceleration.getNorm() > 1e-9 * keplerianAcceleration.getNorm()) {
// we have a relevant acceleration, we can compute derivatives
return true;
} else {
// the provided acceleration is either too small to be reliable (probably even 0), or NaN
return false;
}
}
/** Get the orbit type.
......
......@@ -599,9 +599,8 @@ public class FieldCartesianOrbitTest {
FieldVector3D<T> velocity = new FieldVector3D<>(zero.add(-500.0), zero.add(8000.0), zero.add(1000.0));
T r2 = position.getNormSq();
T r = r2.sqrt();
FieldPVCoordinates<T> pvCoordinates = new FieldPVCoordinates<>(position, velocity,
new FieldVector3D<>(r.multiply(r2).reciprocal().multiply(-mu),
position));
FieldVector3D<T> acceleration = new FieldVector3D<>(r.multiply(r2).reciprocal().multiply(-mu).add(0.1), position);
FieldPVCoordinates<T> pvCoordinates = new FieldPVCoordinates<>(position, velocity,acceleration);
FieldCartesianOrbit<T> fieldOrbit = new FieldCartesianOrbit<>(pvCoordinates, FramesFactory.getEME2000(), date, zero.add(mu));
CartesianOrbit orbit = fieldOrbit.toOrbit();
Assert.assertTrue(orbit.hasDerivatives());
......
......@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.hipparchus.analysis.UnivariateFunction;
import org.hipparchus.analysis.differentiation.DSFactory;
......@@ -1661,6 +1662,29 @@ public class KeplerianOrbitTest {
Assert.assertEquals(0.0, normalized2.getTrueAnomalyDot() - withDerivatives.getTrueAnomalyDot(), 1.0e-10);
}
@Test
public void testKeplerianToPvToKeplerian() {
// setup
Frame eci = FramesFactory.getGCRF();
AbsoluteDate date = AbsoluteDate.ARBITRARY_EPOCH;
double mu = Constants.EGM96_EARTH_MU;
KeplerianOrbit orbit = new KeplerianOrbit(6878e3, 0, 0, 0, 0, 0,
PositionAngle.TRUE, eci, date, mu);
// action
KeplerianOrbit pvOrbit = new KeplerianOrbit(orbit.getPVCoordinates(), eci, mu);
// verify
Assert.assertEquals(orbit.shiftedBy(1).getA(), pvOrbit.shiftedBy(1).getA(), 1e-6);
Assert.assertEquals(orbit.shiftedBy(1).getE(), pvOrbit.shiftedBy(1).getE(), 1e-14);
Assert.assertEquals(orbit.shiftedBy(1).getI(), pvOrbit.shiftedBy(1).getI(), 1e-10);
Assert.assertEquals(orbit.shiftedBy(1).getPerigeeArgument(), pvOrbit.shiftedBy(1).getPerigeeArgument(), 1e-10);
Assert.assertEquals(orbit.shiftedBy(1).getRightAscensionOfAscendingNode(), pvOrbit.shiftedBy(1).getRightAscensionOfAscendingNode(), 1e-10);
Assert.assertEquals(orbit.shiftedBy(1).getTrueAnomaly(), pvOrbit.shiftedBy(1).getTrueAnomaly(), 1e-10);
}
@Before
public void setUp() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment