List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D distance
public static double distance(Vector3D v1, Vector3D v2)
From source file:org.orekit.models.earth.tessellation.Mesh.java
/** Find the existing node closest to a location. * @param location reference location in Cartesian coordinates * @return node or null if no node is available at these indices *//*from w w w . j a va 2 s . c o m*/ public Node getClosestExistingNode(final Vector3D location) { Node selected = null; double min = Double.POSITIVE_INFINITY; for (final Map.Entry<Long, Node> entry : nodes.entrySet()) { final double distance = Vector3D.distance(location, entry.getValue().getV()); if (distance < min) { selected = entry.getValue(); min = distance; } } return selected; }
From source file:org.orekit.orbits.KeplerianParametersTest.java
@Test public void testHyperbola() { KeplerianOrbit orbit = new KeplerianOrbit(-10000000.0, 2.5, 0.3, 0, 0, 0.0, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, mu); Vector3D perigeeP = orbit.getPVCoordinates().getPosition(); Vector3D u = perigeeP.normalize(); Vector3D focus1 = Vector3D.ZERO; Vector3D focus2 = new Vector3D(-2 * orbit.getA() * orbit.getE(), u); for (double dt = -5000; dt < 5000; dt += 60) { PVCoordinates pv = orbit.shiftedBy(dt).getPVCoordinates(); double d1 = Vector3D.distance(pv.getPosition(), focus1); double d2 = Vector3D.distance(pv.getPosition(), focus2); Assert.assertEquals(-2 * orbit.getA(), FastMath.abs(d1 - d2), 1.0e-6); KeplerianOrbit rebuilt = new KeplerianOrbit(pv, orbit.getFrame(), orbit.getDate().shiftedBy(dt), mu); Assert.assertEquals(-10000000.0, rebuilt.getA(), 1.0e-6); Assert.assertEquals(2.5, rebuilt.getE(), 1.0e-13); }//from w w w.j a va2 s.c o m }
From source file:org.orekit.propagation.analytical.EcksteinHechlerPropagatorTest.java
@Test public void sameDateCartesian() throws OrekitException { // Definition of initial conditions with position and velocity // ------------------------------------------------------------ // with e around e = 1.4e-4 and i = 1.7 rad Vector3D position = new Vector3D(3220103., 69623., 6449822.); Vector3D velocity = new Vector3D(6414.7, -2006., -3180.); AbsoluteDate initDate = AbsoluteDate.J2000_EPOCH.shiftedBy(584.); Orbit initialOrbit = new EquinoctialOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), initDate, provider.getMu()); // Extrapolator definition // ----------------------- EcksteinHechlerPropagator extrapolator = new EcksteinHechlerPropagator(initialOrbit, provider); // Extrapolation at the initial date // --------------------------------- SpacecraftState finalOrbit = extrapolator.propagate(initDate); // positions match perfectly Assert.assertEquals(0.0, Vector3D.distance(initialOrbit.getPVCoordinates().getPosition(), finalOrbit.getPVCoordinates().getPosition()), 1.0e-8); // velocity and circular parameters do *not* match, this is EXPECTED! // the reason is that we ensure position/velocity are consistent with the // evolution of the orbit, and this includes the non-Keplerian effects, // whereas the initial orbit is Keplerian only. The implementation of the // model is such that rather than having a perfect match at initial point // (either in velocity or in circular parameters), we have a propagated orbit // that remains close to a numerical reference throughout the orbit. // This is shown in the testInitializationCorrectness() where a numerical // fit is used to check initialization Assert.assertEquals(0.137, Vector3D.distance(initialOrbit.getPVCoordinates().getVelocity(), finalOrbit.getPVCoordinates().getVelocity()), 1.0e-3); Assert.assertEquals(125.2, finalOrbit.getA() - initialOrbit.getA(), 0.1); }
From source file:org.orekit.propagation.analytical.EcksteinHechlerPropagatorTest.java
@Test public void sameDateKeplerian() throws OrekitException { // Definition of initial conditions with keplerian parameters // ----------------------------------------------------------- AbsoluteDate initDate = AbsoluteDate.J2000_EPOCH.shiftedBy(584.); Orbit initialOrbit = new KeplerianOrbit(7209668.0, 0.5e-4, 1.7, 2.1, 2.9, 6.2, PositionAngle.TRUE, FramesFactory.getEME2000(), initDate, provider.getMu()); // Extrapolator definition // ----------------------- EcksteinHechlerPropagator extrapolator = new EcksteinHechlerPropagator(initialOrbit, Propagator.DEFAULT_MASS, provider); // Extrapolation at the initial date // --------------------------------- SpacecraftState finalOrbit = extrapolator.propagate(initDate); // positions match perfectly Assert.assertEquals(0.0, Vector3D.distance(initialOrbit.getPVCoordinates().getPosition(), finalOrbit.getPVCoordinates().getPosition()), 3.0e-8); // velocity and circular parameters do *not* match, this is EXPECTED! // the reason is that we ensure position/velocity are consistent with the // evolution of the orbit, and this includes the non-Keplerian effects, // whereas the initial orbit is Keplerian only. The implementation of the // model is such that rather than having a perfect match at initial point // (either in velocity or in circular parameters), we have a propagated orbit // that remains close to a numerical reference throughout the orbit. // This is shown in the testInitializationCorrectness() where a numerical // fit is used to check initialization Assert.assertEquals(0.137, Vector3D.distance(initialOrbit.getPVCoordinates().getVelocity(), finalOrbit.getPVCoordinates().getVelocity()), 1.0e-3); Assert.assertEquals(126.8, finalOrbit.getA() - initialOrbit.getA(), 0.1); }
From source file:org.orekit.propagation.analytical.EcksteinHechlerPropagatorTest.java
@Test public void testAcceleration() throws OrekitException { final KeplerianOrbit orbit = new KeplerianOrbit(7.8e6, 0.032, 0.4, 0.1, 0.2, 0.3, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, provider.getMu()); EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(orbit, provider); AbsoluteDate target = AbsoluteDate.J2000_EPOCH.shiftedBy(10000.0); List<TimeStampedPVCoordinates> sample = new ArrayList<TimeStampedPVCoordinates>(); for (double dt : Arrays.asList(-0.5, 0.0, 0.5)) { sample.add(propagator.propagate(target.shiftedBy(dt)).getPVCoordinates()); }//from w w w . j a v a 2s . c o m TimeStampedPVCoordinates interpolated = TimeStampedPVCoordinates.interpolate(target, CartesianDerivativesFilter.USE_P, sample); Vector3D computedP = sample.get(1).getPosition(); Vector3D computedV = sample.get(1).getVelocity(); Vector3D referenceP = interpolated.getPosition(); Vector3D referenceV = interpolated.getVelocity(); Vector3D computedA = sample.get(1).getAcceleration(); Vector3D referenceA = interpolated.getAcceleration(); final CircularOrbit propagated = (CircularOrbit) OrbitType.CIRCULAR .convertType(propagator.propagateOrbit(target)); final CircularOrbit keplerian = new CircularOrbit(propagated.getA(), propagated.getCircularEx(), propagated.getCircularEy(), propagated.getI(), propagated.getRightAscensionOfAscendingNode(), propagated.getAlphaM(), PositionAngle.MEAN, propagated.getFrame(), propagated.getDate(), propagated.getMu()); Vector3D keplerianP = keplerian.getPVCoordinates().getPosition(); Vector3D keplerianV = keplerian.getPVCoordinates().getVelocity(); Vector3D keplerianA = keplerian.getPVCoordinates().getAcceleration(); // perturbed orbit position should be similar to Keplerian orbit position Assert.assertEquals(0.0, Vector3D.distance(referenceP, computedP), 1.0e-15); Assert.assertEquals(0.0, Vector3D.distance(referenceP, keplerianP), 4.0e-9); // perturbed orbit velocity should be equal to Keplerian orbit because // it was in fact reconstructed from Cartesian coordinates double computationErrorV = Vector3D.distance(referenceV, computedV); double nonKeplerianEffectV = Vector3D.distance(referenceV, keplerianV); Assert.assertEquals(nonKeplerianEffectV, computationErrorV, 9.0e-13); Assert.assertEquals(2.2e-4, computationErrorV, 3.0e-6); // perturbed orbit acceleration should be different from Keplerian orbit because // Keplerian orbit doesn't take orbit shape changes into account // perturbed orbit acceleration should be consistent with position evolution double computationErrorA = Vector3D.distance(referenceA, computedA); double nonKeplerianEffectA = Vector3D.distance(referenceA, keplerianA); Assert.assertEquals(1.0e-7, computationErrorA, 6.0e-9); Assert.assertEquals(6.37e-3, nonKeplerianEffectA, 7.0e-6); Assert.assertTrue(computationErrorA < nonKeplerianEffectA / 60000); }
From source file:org.orekit.propagation.analytical.EcksteinHechlerPropagatorTest.java
@Test public void testInitializationCorrectness() throws OrekitException, IOException { // Definition of initial conditions AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(154.); Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true); Frame eme2000 = FramesFactory.getEME2000(); Vector3D pole = itrf.getTransformTo(eme2000, date).transformVector(Vector3D.PLUS_K); Frame poleAligned = new Frame(FramesFactory.getEME2000(), new Transform(date, new Rotation(pole, Vector3D.PLUS_K)), "pole aligned", true); CircularOrbit initial = new CircularOrbit(7208669.8179538045, 1.3740461966386876E-4, -3.2364250248363356E-5, FastMath.toRadians(97.40236024565775), FastMath.toRadians(166.15873160992115), FastMath.toRadians(90.1282370098961), PositionAngle.MEAN, poleAligned, date, provider.getMu()); // find the default Eckstein-Hechler propagator initialized from the initial orbit EcksteinHechlerPropagator defaultEH = new EcksteinHechlerPropagator(initial, provider); // the osculating parameters recomputed by the default Eckstein-Hechler propagator are quite different // from initial orbit CircularOrbit defaultOrbit = (CircularOrbit) OrbitType.CIRCULAR .convertType(defaultEH.propagateOrbit(initial.getDate())); Assert.assertEquals(267.4, defaultOrbit.getA() - initial.getA(), 0.1); // the position on the other hand match perfectly Assert.assertEquals(0.0, Vector3D.distance(defaultOrbit.getPVCoordinates().getPosition(), initial.getPVCoordinates().getPosition()), 1.0e-8); // set up a reference numerical propagator starting for the specified start orbit // using the same force models (i.e. the first few zonal terms) double[][] tol = NumericalPropagator.tolerances(0.1, initial, OrbitType.CIRCULAR); AdaptiveStepsizeIntegrator integrator = new DormandPrince853Integrator(0.001, 1000, tol[0], tol[1]); integrator.setInitialStepSize(60);/*from ww w.ja v a 2 s . co m*/ NumericalPropagator num = new NumericalPropagator(integrator); num.addForceModel( new HolmesFeatherstoneAttractionModel(itrf, GravityFieldFactory.getNormalizedProvider(provider))); num.setInitialState(new SpacecraftState(initial)); num.setOrbitType(OrbitType.CIRCULAR); // find the best Eckstein-Hechler propagator that match the orbit evolution PropagatorConverter converter = new FiniteDifferencePropagatorConverter( new EcksteinHechlerPropagatorBuilder(poleAligned, provider, OrbitType.CIRCULAR, PositionAngle.TRUE), 1.0e-6, 100); EcksteinHechlerPropagator fittedEH = (EcksteinHechlerPropagator) converter.convert(num, 3 * initial.getKeplerianPeriod(), 300); // the default Eckstein-Hechler propagator did however quite a good job, as it found // an orbit close to the best fitting CircularOrbit fittedOrbit = (CircularOrbit) OrbitType.CIRCULAR .convertType(fittedEH.propagateOrbit(initial.getDate())); Assert.assertEquals(0.623, defaultOrbit.getA() - fittedOrbit.getA(), 0.1); // the position on the other hand are slightly different // because the fitted orbit minimizes the residuals over a complete time span, // not on a single point Assert.assertEquals(58.0, Vector3D.distance(defaultOrbit.getPVCoordinates().getPosition(), fittedOrbit.getPVCoordinates().getPosition()), 0.1); }
From source file:org.orekit.propagation.analytical.KeplerianPropagatorTest.java
@Test public void testMu() throws OrekitException { final KeplerianOrbit orbit1 = new KeplerianOrbit(7.8e6, 0.032, 0.4, 0.1, 0.2, 0.3, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, Constants.WGS84_EARTH_MU); final KeplerianOrbit orbit2 = new KeplerianOrbit(7.8e6, 0.032, 0.4, 0.1, 0.2, 0.3, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, Constants.EIGEN5C_EARTH_MU); final AbsoluteDate target = orbit1.getDate().shiftedBy(10000.0); PVCoordinates pv1 = new KeplerianPropagator(orbit1).propagate(target).getPVCoordinates(); PVCoordinates pv2 = new KeplerianPropagator(orbit2).propagate(target).getPVCoordinates(); PVCoordinates pvWithMu1 = new KeplerianPropagator(orbit2, orbit1.getMu()).propagate(target) .getPVCoordinates();/*from ww w. j a va2 s. c o m*/ Assert.assertEquals(0.026054, Vector3D.distance(pv1.getPosition(), pv2.getPosition()), 1.0e-6); Assert.assertEquals(0.0, Vector3D.distance(pv1.getPosition(), pvWithMu1.getPosition()), 1.0e-15); }
From source file:org.orekit.propagation.analytical.TabulatedEphemerisTest.java
private void checkInterpolation(StateFilter f, double expectedDP, double expectedDV) throws OrekitException { double mass = 2500; double a = 7187990.1979844316; double e = 0.5e-4; double i = 1.7105407051081795; double omega = 1.9674147913622104; double OMEGA = FastMath.toRadians(261); double lv = 0; final AbsoluteDate initDate = new AbsoluteDate(new DateComponents(2004, 01, 01), TimeComponents.H00, TimeScalesFactory.getUTC()); final AbsoluteDate finalDate = new AbsoluteDate(new DateComponents(2004, 01, 02), TimeComponents.H00, TimeScalesFactory.getUTC()); double deltaT = finalDate.durationFrom(initDate); Orbit transPar = new KeplerianOrbit(a, e, i, omega, OMEGA, lv, PositionAngle.TRUE, FramesFactory.getEME2000(), initDate, mu); int nbIntervals = 720; EcksteinHechlerPropagator eck = new EcksteinHechlerPropagator(transPar, mass, ae, mu, c20, c30, c40, c50, c60);/*from ww w .j av a2 s . co m*/ AdditionalStateProvider provider = new AdditionalStateProvider() { public String getName() { return "dt"; } public double[] getAdditionalState(SpacecraftState state) { return new double[] { state.getDate().durationFrom(initDate) }; } }; eck.addAdditionalStateProvider(provider); try { eck.addAdditionalStateProvider(provider); Assert.fail("an exception should have been thrown"); } catch (OrekitException oe) { Assert.assertEquals(OrekitMessages.ADDITIONAL_STATE_NAME_ALREADY_IN_USE, oe.getSpecifier()); } List<SpacecraftState> tab = new ArrayList<SpacecraftState>(nbIntervals + 1); for (int j = 0; j <= nbIntervals; j++) { AbsoluteDate current = initDate.shiftedBy((j * deltaT) / nbIntervals); tab.add(f.filter(eck.propagate(current))); } try { new Ephemeris(tab, nbIntervals + 2); Assert.fail("an exception should have been thrown"); } catch (MathIllegalArgumentException miae) { // expected } Ephemeris te = new Ephemeris(tab, 2); Assert.assertEquals(0.0, te.getMaxDate().durationFrom(finalDate), 1.0e-9); Assert.assertEquals(0.0, te.getMinDate().durationFrom(initDate), 1.0e-9); double maxP = 0; double maxV = 0; for (double dt = 0; dt < 3600; dt += 1) { AbsoluteDate date = initDate.shiftedBy(dt); CartesianOrbit c1 = (CartesianOrbit) eck.propagate(date).getOrbit(); CartesianOrbit c2 = (CartesianOrbit) te.propagate(date).getOrbit(); maxP = FastMath.max(maxP, Vector3D.distance(c1.getPVCoordinates().getPosition(), c2.getPVCoordinates().getPosition())); maxV = FastMath.max(maxV, Vector3D.distance(c1.getPVCoordinates().getVelocity(), c2.getPVCoordinates().getVelocity())); } Assert.assertEquals(expectedDP, maxP, 0.1 * expectedDP); Assert.assertEquals(expectedDV, maxV, 0.1 * expectedDV); }
From source file:org.orekit.propagation.analytical.TabulatedEphemerisTest.java
@Test public void testPiWraping() throws OrekitException { TimeScale utc = TimeScalesFactory.getUTC(); Frame frame = FramesFactory.getEME2000(); double mu = CelestialBodyFactory.getEarth().getGM(); AbsoluteDate t0 = new AbsoluteDate(2009, 10, 29, 0, 0, 0, utc); AbsoluteDate t1 = new AbsoluteDate(t0, 1320.0); Vector3D p1 = new Vector3D(-0.17831296727974E+08, 0.67919502669856E+06, -0.16591008368477E+07); Vector3D v1 = new Vector3D(-0.38699705630724E+04, -0.36209408682762E+04, -0.16255053872347E+03); SpacecraftState s1 = new SpacecraftState(new EquinoctialOrbit(new PVCoordinates(p1, v1), frame, t1, mu)); AbsoluteDate t2 = new AbsoluteDate(t0, 1440.0); Vector3D p2 = new Vector3D(-0.18286942572033E+08, 0.24442124296930E+06, -0.16777961761695E+07); Vector3D v2 = new Vector3D(-0.37252897467918E+04, -0.36246628128896E+04, -0.14917724596280E+03); SpacecraftState s2 = new SpacecraftState(new EquinoctialOrbit(new PVCoordinates(p2, v2), frame, t2, mu)); AbsoluteDate t3 = new AbsoluteDate(t0, 1560.0); Vector3D p3 = new Vector3D(-0.18725635245837E+08, -0.19058407701834E+06, -0.16949352249614E+07); Vector3D v3 = new Vector3D(-0.35873348682393E+04, -0.36248828501784E+04, -0.13660045394149E+03); SpacecraftState s3 = new SpacecraftState(new EquinoctialOrbit(new PVCoordinates(p3, v3), frame, t3, mu)); Ephemeris ephem = new Ephemeris(Arrays.asList(s1, s2, s3), 2); AbsoluteDate tA = new AbsoluteDate(t0, 24 * 60); Vector3D pA = ephem.propagate(tA).getPVCoordinates(frame).getPosition(); Assert.assertEquals(1.766, Vector3D.distance(pA, s1.shiftedBy(tA.durationFrom(s1.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); Assert.assertEquals(0.000, Vector3D.distance(pA, s2.shiftedBy(tA.durationFrom(s2.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); Assert.assertEquals(1.556, Vector3D.distance(pA, s3.shiftedBy(tA.durationFrom(s3.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); AbsoluteDate tB = new AbsoluteDate(t0, 25 * 60); Vector3D pB = ephem.propagate(tB).getPVCoordinates(frame).getPosition(); Assert.assertEquals(2.646, Vector3D.distance(pB, s1.shiftedBy(tB.durationFrom(s1.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); Assert.assertEquals(2.619, Vector3D.distance(pB, s2.shiftedBy(tB.durationFrom(s2.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); Assert.assertEquals(2.632, Vector3D.distance(pB, s3.shiftedBy(tB.durationFrom(s3.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); AbsoluteDate tC = new AbsoluteDate(t0, 26 * 60); Vector3D pC = ephem.propagate(tC).getPVCoordinates(frame).getPosition(); Assert.assertEquals(6.851, Vector3D.distance(pC, s1.shiftedBy(tC.durationFrom(s1.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); Assert.assertEquals(1.605, Vector3D.distance(pC, s2.shiftedBy(tC.durationFrom(s2.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); Assert.assertEquals(0.000, Vector3D.distance(pC, s3.shiftedBy(tC.durationFrom(s3.getDate())).getPVCoordinates(frame).getPosition()), 1.0e-3); }
From source file:org.orekit.propagation.SpacecraftStateTest.java
@Test public void testSerialization() throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, OrekitException { propagator.resetInitialState(/*from ww w. j a v a 2s. co m*/ propagator.getInitialState().addAdditionalState("p1", 12.25).addAdditionalState("p2", 1, 2, 3)); SpacecraftState state = propagator.propagate(orbit.getDate().shiftedBy(123.456)); Assert.assertEquals(2, state.getAdditionalStates().size()); Assert.assertEquals(1, state.getAdditionalState("p1").length); Assert.assertEquals(12.25, state.getAdditionalState("p1")[0], 1.0e-15); Assert.assertEquals(3, state.getAdditionalState("p2").length); Assert.assertEquals(1.0, state.getAdditionalState("p2")[0], 1.0e-15); Assert.assertEquals(2.0, state.getAdditionalState("p2")[1], 1.0e-15); Assert.assertEquals(3.0, state.getAdditionalState("p2")[2], 1.0e-15); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(state); Assert.assertTrue(bos.size() > 700); Assert.assertTrue(bos.size() < 800); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bis); SpacecraftState deserialized = (SpacecraftState) ois.readObject(); Assert.assertEquals(0.0, Vector3D.distance(state.getPVCoordinates().getPosition(), deserialized.getPVCoordinates().getPosition()), 1.0e-10); Assert.assertEquals(0.0, Vector3D.distance(state.getPVCoordinates().getVelocity(), deserialized.getPVCoordinates().getVelocity()), 1.0e-10); Assert.assertEquals(0.0, Rotation.distance(state.getAttitude().getRotation(), deserialized.getAttitude().getRotation()), 1.0e-10); Assert.assertEquals(0.0, Vector3D.distance(state.getAttitude().getSpin(), deserialized.getAttitude().getSpin()), 1.0e-10); Assert.assertEquals(state.getDate(), deserialized.getDate()); Assert.assertEquals(state.getMu(), deserialized.getMu(), 1.0e-10); Assert.assertEquals(state.getFrame().getName(), deserialized.getFrame().getName()); Assert.assertEquals(2, deserialized.getAdditionalStates().size()); Assert.assertEquals(1, deserialized.getAdditionalState("p1").length); Assert.assertEquals(12.25, deserialized.getAdditionalState("p1")[0], 1.0e-15); Assert.assertEquals(3, deserialized.getAdditionalState("p2").length); Assert.assertEquals(1.0, deserialized.getAdditionalState("p2")[0], 1.0e-15); Assert.assertEquals(2.0, deserialized.getAdditionalState("p2")[1], 1.0e-15); Assert.assertEquals(3.0, deserialized.getAdditionalState("p2")[2], 1.0e-15); }