List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Rotation distance
public static double distance(Rotation r1, Rotation r2)
From source file:org.orekit.attitudes.AttitudeTest.java
@Test public void testZeroRate() throws OrekitException { Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(), new Rotation(0.48, 0.64, 0.36, 0.48, false), Vector3D.ZERO, Vector3D.ZERO); Assert.assertEquals(Vector3D.ZERO, attitude.getSpin()); double dt = 10.0; Attitude shifted = attitude.shiftedBy(dt); Assert.assertEquals(Vector3D.ZERO, shifted.getRotationAcceleration()); Assert.assertEquals(Vector3D.ZERO, shifted.getSpin()); Assert.assertEquals(0.0, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-15); }
From source file:org.orekit.attitudes.AttitudeTest.java
@Test public void testShift() throws OrekitException { double rate = 2 * FastMath.PI / (12 * 60); Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(), Rotation.IDENTITY, new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO); Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10); double dt = 10.0; double alpha = rate * dt; Attitude shifted = attitude.shiftedBy(dt); Assert.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10); Assert.assertEquals(alpha, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10); Vector3D xSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I); Assert.assertEquals(0.0, xSat.subtract(new Vector3D(FastMath.cos(alpha), FastMath.sin(alpha), 0)).getNorm(), 1.0e-10);/*from w ww . ja v a 2s .c o m*/ Vector3D ySat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J); Assert.assertEquals(0.0, ySat.subtract(new Vector3D(-FastMath.sin(alpha), FastMath.cos(alpha), 0)).getNorm(), 1.0e-10); Vector3D zSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K); Assert.assertEquals(0.0, zSat.subtract(Vector3D.PLUS_K).getNorm(), 1.0e-10); }
From source file:org.orekit.attitudes.AttitudeTest.java
@Test public void testSpin() throws OrekitException { double rate = 2 * FastMath.PI / (12 * 60); Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(), new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO); Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10); double dt = 10.0; Attitude shifted = attitude.shiftedBy(dt); Assert.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10); Assert.assertEquals(rate * dt, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10); Vector3D shiftedX = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I); Vector3D shiftedY = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J); Vector3D shiftedZ = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K); Vector3D originalX = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I); Vector3D originalY = attitude.getRotation().applyInverseTo(Vector3D.PLUS_J); Vector3D originalZ = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K); Assert.assertEquals(FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedX, originalX), 1.0e-10); Assert.assertEquals(FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedX, originalY), 1.0e-10); Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedX, originalZ), 1.0e-10); Assert.assertEquals(-FastMath.sin(rate * dt), Vector3D.dotProduct(shiftedY, originalX), 1.0e-10); Assert.assertEquals(FastMath.cos(rate * dt), Vector3D.dotProduct(shiftedY, originalY), 1.0e-10); Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedY, originalZ), 1.0e-10); Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedZ, originalX), 1.0e-10); Assert.assertEquals(0.0, Vector3D.dotProduct(shiftedZ, originalY), 1.0e-10); Assert.assertEquals(1.0, Vector3D.dotProduct(shiftedZ, originalZ), 1.0e-10); Vector3D forward = AngularCoordinates.estimateRate(attitude.getRotation(), shifted.getRotation(), dt); Assert.assertEquals(0.0, forward.subtract(attitude.getSpin()).getNorm(), 1.0e-10); Vector3D reversed = AngularCoordinates.estimateRate(shifted.getRotation(), attitude.getRotation(), dt); Assert.assertEquals(0.0, reversed.add(attitude.getSpin()).getNorm(), 1.0e-10); }
From source file:org.orekit.attitudes.AttitudeTest.java
@Test public void testInterpolation() throws OrekitException { Utils.setDataRoot("regular-data"); final double ehMu = 3.9860047e14; final double ae = 6.378137e6; final double c20 = -1.08263e-3; final double c30 = 2.54e-6; final double c40 = 1.62e-6; final double c50 = 2.3e-7; final double c60 = -5.5e-7; final AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(584.); final Vector3D position = new Vector3D(3220103., 69623., 6449822.); final Vector3D velocity = new Vector3D(6414.7, -2006., -3180.); final CircularOrbit initialOrbit = new CircularOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), date, ehMu); EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(initialOrbit, ae, ehMu, c20, c30, c40, c50, c60);//from w w w. j a v a 2 s . c o m OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true)); propagator.setAttitudeProvider(new BodyCenterPointing(initialOrbit.getFrame(), earth)); final Attitude initialAttitude = propagator.propagate(initialOrbit.getDate()).getAttitude(); // set up a 5 points sample List<Attitude> sample = new ArrayList<Attitude>(); for (double dt = 0; dt < 251.0; dt += 60.0) { sample.add(propagator.propagate(date.shiftedBy(dt)).getAttitude()); } // well inside the sample, interpolation should be better than quadratic shift double maxShiftAngleError = 0; double maxInterpolationAngleError = 0; double maxShiftRateError = 0; double maxInterpolationRateError = 0; for (double dt = 0; dt < 240.0; dt += 1.0) { AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt); Attitude propagated = propagator.propagate(t).getAttitude(); double shiftAngleError = Rotation.distance(propagated.getRotation(), initialAttitude.shiftedBy(dt).getRotation()); double interpolationAngleError = Rotation.distance(propagated.getRotation(), initialAttitude.interpolate(t, sample).getRotation()); double shiftRateError = Vector3D.distance(propagated.getSpin(), initialAttitude.shiftedBy(dt).getSpin()); double interpolationRateError = Vector3D.distance(propagated.getSpin(), initialAttitude.interpolate(t, sample).getSpin()); maxShiftAngleError = FastMath.max(maxShiftAngleError, shiftAngleError); maxInterpolationAngleError = FastMath.max(maxInterpolationAngleError, interpolationAngleError); maxShiftRateError = FastMath.max(maxShiftRateError, shiftRateError); maxInterpolationRateError = FastMath.max(maxInterpolationRateError, interpolationRateError); } Assert.assertTrue(maxShiftAngleError > 4.0e-6); Assert.assertTrue(maxInterpolationAngleError < 1.5e-13); Assert.assertTrue(maxShiftRateError > 6.0e-8); Assert.assertTrue(maxInterpolationRateError < 2.5e-14); // past sample end, interpolation error should increase, but still be far better than quadratic shift maxShiftAngleError = 0; maxInterpolationAngleError = 0; maxShiftRateError = 0; maxInterpolationRateError = 0; for (double dt = 250.0; dt < 300.0; dt += 1.0) { AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt); Attitude propagated = propagator.propagate(t).getAttitude(); double shiftAngleError = Rotation.distance(propagated.getRotation(), initialAttitude.shiftedBy(dt).getRotation()); double interpolationAngleError = Rotation.distance(propagated.getRotation(), initialAttitude.interpolate(t, sample).getRotation()); double shiftRateError = Vector3D.distance(propagated.getSpin(), initialAttitude.shiftedBy(dt).getSpin()); double interpolationRateError = Vector3D.distance(propagated.getSpin(), initialAttitude.interpolate(t, sample).getSpin()); maxShiftAngleError = FastMath.max(maxShiftAngleError, shiftAngleError); maxInterpolationAngleError = FastMath.max(maxInterpolationAngleError, interpolationAngleError); maxShiftRateError = FastMath.max(maxShiftRateError, shiftRateError); maxInterpolationRateError = FastMath.max(maxInterpolationRateError, interpolationRateError); } Assert.assertTrue(maxShiftAngleError > 9.0e-6); Assert.assertTrue(maxInterpolationAngleError < 6.0e-11); Assert.assertTrue(maxShiftRateError > 9.0e-8); Assert.assertTrue(maxInterpolationRateError < 4.0e-12); }
From source file:org.orekit.attitudes.BodyCenterPointingTest.java
@Test public void testSpin() throws OrekitException { Utils.setDataRoot("regular-data"); final double ehMu = 3.9860047e14; final double ae = 6.378137e6; final double c20 = -1.08263e-3; final double c30 = 2.54e-6; final double c40 = 1.62e-6; final double c50 = 2.3e-7; final double c60 = -5.5e-7; final AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(584.); final Vector3D position = new Vector3D(3220103., 69623., 6449822.); final Vector3D velocity = new Vector3D(6414.7, -2006., -3180.); final CircularOrbit initialOrbit = new CircularOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), date, ehMu); EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(initialOrbit, ae, ehMu, c20, c30, c40, c50, c60);//from w ww .j a va 2s . com propagator.setAttitudeProvider(earthCenterAttitudeLaw); double h = 0.01; SpacecraftState s0 = propagator.propagate(date); SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h)); SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h)); // check spin is consistent with attitude evolution double errorAngleMinus = Rotation.distance(sMinus.shiftedBy(h).getAttitude().getRotation(), s0.getAttitude().getRotation()); double evolutionAngleMinus = Rotation.distance(sMinus.getAttitude().getRotation(), s0.getAttitude().getRotation()); Assert.assertEquals(0.0, errorAngleMinus, 1.0e-6 * evolutionAngleMinus); double errorAnglePlus = Rotation.distance(s0.getAttitude().getRotation(), sPlus.shiftedBy(-h).getAttitude().getRotation()); double evolutionAnglePlus = Rotation.distance(s0.getAttitude().getRotation(), sPlus.getAttitude().getRotation()); Assert.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus); Vector3D spin0 = s0.getAttitude().getSpin(); Vector3D reference = AngularCoordinates.estimateRate(sMinus.getAttitude().getRotation(), sPlus.getAttitude().getRotation(), 2 * h); Assert.assertTrue(spin0.getNorm() > 1.0e-3); Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 1.0e-13); }
From source file:org.orekit.attitudes.CelestialBodyPointingTest.java
@Test public void testSunPointing() throws OrekitException { PVCoordinatesProvider sun = CelestialBodyFactory.getSun(); final Frame frame = FramesFactory.getGCRF(); AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789), TimeScalesFactory.getTAI()); AttitudeProvider sunPointing = new CelestialBodyPointed(frame, sun, Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_K);// w w w . j a va 2 s . c om PVCoordinates pv = new PVCoordinates(new Vector3D(28812595.32120171334, 5948437.45881852374, 0.0), new Vector3D(0, 0, 3680.853673522056)); Orbit orbit = new KeplerianOrbit(pv, frame, date, 3.986004415e14); Attitude attitude = sunPointing.getAttitude(orbit, date, frame); Vector3D xDirection = attitude.getRotation().applyInverseTo(Vector3D.PLUS_I); Vector3D zDirection = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K); Assert.assertEquals(0, Vector3D.dotProduct(zDirection, Vector3D.crossProduct(xDirection, Vector3D.PLUS_K)), 1.0e-15); // the following statement checks we take parallax into account // Sun-Earth-Sat are in quadrature, with distance (Earth, Sat) == distance(Sun, Earth) / 5000 Assert.assertEquals(FastMath.atan(1.0 / 5000.0), Vector3D.angle(xDirection, sun.getPVCoordinates(date, frame).getPosition()), 1.0e-15); double h = 0.1; Attitude aMinus = sunPointing.getAttitude(orbit.shiftedBy(-h), date.shiftedBy(-h), frame); Attitude a0 = sunPointing.getAttitude(orbit, date, frame); Attitude aPlus = sunPointing.getAttitude(orbit.shiftedBy(h), date.shiftedBy(h), frame); // check spin is consistent with attitude evolution double errorAngleMinus = Rotation.distance(aMinus.shiftedBy(h).getRotation(), a0.getRotation()); double evolutionAngleMinus = Rotation.distance(aMinus.getRotation(), a0.getRotation()); Assert.assertEquals(0.0, errorAngleMinus, 1.0e-6 * evolutionAngleMinus); double errorAnglePlus = Rotation.distance(a0.getRotation(), aPlus.shiftedBy(-h).getRotation()); double evolutionAnglePlus = Rotation.distance(a0.getRotation(), aPlus.getRotation()); Assert.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus); }
From source file:org.orekit.attitudes.FixedRateTest.java
@Test public void testZeroRate() throws OrekitException { AbsoluteDate date = new AbsoluteDate(new DateComponents(2004, 3, 2), new TimeComponents(13, 17, 7.865), TimeScalesFactory.getUTC()); final Frame frame = FramesFactory.getEME2000(); FixedRate law = new FixedRate(new Attitude(date, frame, new Rotation(0.48, 0.64, 0.36, 0.48, false), Vector3D.ZERO, Vector3D.ZERO)); PVCoordinates pv = new PVCoordinates(new Vector3D(28812595.32012577, 5948437.4640250085, 0), new Vector3D(0, 0, 3680.853673522056)); Orbit orbit = new KeplerianOrbit(pv, frame, date, 3.986004415e14); Rotation attitude0 = law.getAttitude(orbit, date, frame).getRotation(); Assert.assertEquals(0, Rotation.distance(attitude0, law.getReferenceAttitude().getRotation()), 1.0e-10); Rotation attitude1 = law.getAttitude(orbit.shiftedBy(10.0), date.shiftedBy(10.0), frame).getRotation(); Assert.assertEquals(0, Rotation.distance(attitude1, law.getReferenceAttitude().getRotation()), 1.0e-10); Rotation attitude2 = law.getAttitude(orbit.shiftedBy(20.0), date.shiftedBy(20.0), frame).getRotation(); Assert.assertEquals(0, Rotation.distance(attitude2, law.getReferenceAttitude().getRotation()), 1.0e-10); }
From source file:org.orekit.attitudes.FixedRateTest.java
@Test public void testNonZeroRate() throws OrekitException { final AbsoluteDate date = new AbsoluteDate(new DateComponents(2004, 3, 2), new TimeComponents(13, 17, 7.865), TimeScalesFactory.getUTC()); final double rate = 2 * FastMath.PI / (12 * 60); final Frame frame = FramesFactory.getEME2000(); FixedRate law = new FixedRate(new Attitude(date, frame, new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO)); PVCoordinates pv = new PVCoordinates(new Vector3D(28812595.32012577, 5948437.4640250085, 0), new Vector3D(0, 0, 3680.853673522056)); Orbit orbit = new KeplerianOrbit(pv, FramesFactory.getEME2000(), date, 3.986004415e14); Rotation attitude0 = law.getAttitude(orbit, date, frame).getRotation(); Assert.assertEquals(0, Rotation.distance(attitude0, law.getReferenceAttitude().getRotation()), 1.0e-10); Rotation attitude1 = law.getAttitude(orbit.shiftedBy(10.0), date.shiftedBy(10.0), frame).getRotation(); Assert.assertEquals(10 * rate, Rotation.distance(attitude1, law.getReferenceAttitude().getRotation()), 1.0e-10);/*w ww . ja v a 2 s . c o m*/ Rotation attitude2 = law.getAttitude(orbit.shiftedBy(-20.0), date.shiftedBy(-20.0), frame).getRotation(); Assert.assertEquals(20 * rate, Rotation.distance(attitude2, law.getReferenceAttitude().getRotation()), 1.0e-10); Assert.assertEquals(30 * rate, Rotation.distance(attitude2, attitude1), 1.0e-10); Rotation attitude3 = law.getAttitude(orbit.shiftedBy(0.0), date, frame).getRotation(); Assert.assertEquals(0, Rotation.distance(attitude3, law.getReferenceAttitude().getRotation()), 1.0e-10); }
From source file:org.orekit.attitudes.FixedRateTest.java
@Test public void testSpin() throws OrekitException { AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789), TimeScalesFactory.getUTC()); final double rate = 2 * FastMath.PI / (12 * 60); AttitudeProvider law = new FixedRate(new Attitude(date, FramesFactory.getEME2000(), new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO)); KeplerianOrbit orbit = new KeplerianOrbit(7178000.0, 1.e-4, FastMath.toRadians(50.), FastMath.toRadians(10.), FastMath.toRadians(20.), FastMath.toRadians(30.), PositionAngle.MEAN, FramesFactory.getEME2000(), date, 3.986004415e14); Propagator propagator = new KeplerianPropagator(orbit, law); double h = 0.01; SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h)); SpacecraftState s0 = propagator.propagate(date); SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h)); // check spin is consistent with attitude evolution double errorAngleMinus = Rotation.distance(sMinus.shiftedBy(h).getAttitude().getRotation(), s0.getAttitude().getRotation()); double evolutionAngleMinus = Rotation.distance(sMinus.getAttitude().getRotation(), s0.getAttitude().getRotation()); Assert.assertEquals(0.0, errorAngleMinus, 1.0e-6 * evolutionAngleMinus); double errorAnglePlus = Rotation.distance(s0.getAttitude().getRotation(), sPlus.shiftedBy(-h).getAttitude().getRotation()); double evolutionAnglePlus = Rotation.distance(s0.getAttitude().getRotation(), sPlus.getAttitude().getRotation()); Assert.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus); Vector3D spin0 = s0.getAttitude().getSpin(); Vector3D reference = AngularCoordinates.estimateRate(sMinus.getAttitude().getRotation(), sPlus.getAttitude().getRotation(), 2 * h); Assert.assertEquals(0.0, spin0.subtract(reference).getNorm(), 1.0e-14); }
From source file:org.orekit.attitudes.InertialAttitudeTest.java
@Test public void testSpin() throws OrekitException { AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 01, 01), new TimeComponents(3, 25, 45.6789), TimeScalesFactory.getUTC()); AttitudeProvider law = new InertialProvider(new Rotation(new Vector3D(-0.64, 0.6, 0.48), 0.2)); KeplerianOrbit orbit = new KeplerianOrbit(7178000.0, 1.e-4, FastMath.toRadians(50.), FastMath.toRadians(10.), FastMath.toRadians(20.), FastMath.toRadians(30.), PositionAngle.MEAN, FramesFactory.getEME2000(), date, 3.986004415e14); Propagator propagator = new KeplerianPropagator(orbit, law); double h = 100.0; SpacecraftState sMinus = propagator.propagate(date.shiftedBy(-h)); SpacecraftState s0 = propagator.propagate(date); SpacecraftState sPlus = propagator.propagate(date.shiftedBy(h)); // check spin is consistent with attitude evolution double errorAngleMinus = Rotation.distance(sMinus.shiftedBy(h).getAttitude().getRotation(), s0.getAttitude().getRotation()); double evolutionAngleMinus = Rotation.distance(sMinus.getAttitude().getRotation(), s0.getAttitude().getRotation()); Assert.assertEquals(0.0, errorAngleMinus, 1.0e-6 * evolutionAngleMinus); double errorAnglePlus = Rotation.distance(s0.getAttitude().getRotation(), sPlus.shiftedBy(-h).getAttitude().getRotation()); double evolutionAnglePlus = Rotation.distance(s0.getAttitude().getRotation(), sPlus.getAttitude().getRotation()); Assert.assertEquals(0.0, errorAnglePlus, 1.0e-6 * evolutionAnglePlus); // compute spin axis using finite differences Rotation rMinus = sMinus.getAttitude().getRotation(); Rotation rPlus = sPlus.getAttitude().getRotation(); Rotation dr = rPlus.applyTo(rMinus.revert()); Assert.assertEquals(0, dr.getAngle(), 1.0e-10); Vector3D spin0 = s0.getAttitude().getSpin(); Assert.assertEquals(0, spin0.getNorm(), 1.0e-10); }