Example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D ZERO

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D ZERO

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D ZERO.

Prototype

Vector3D ZERO

To view the source code for org.apache.commons.math3.geometry.euclidean.threed Vector3D ZERO.

Click Source Link

Document

Null vector (coordinates: 0, 0, 0).

Usage

From source file:org.orekit.propagation.analytical.AdapterPropagatorTest.java

@Test
public void testNonKeplerian() throws OrekitException, ParseException, IOException {

    Orbit leo = new CircularOrbit(7204319.233600575, 4.434564637450575E-4, 0.0011736728299091088,
            1.7211611441767323, 5.5552084166959474, 24950.321259193086, PositionAngle.TRUE,
            FramesFactory.getEME2000(), new AbsoluteDate(new DateComponents(2003, 9, 16),
                    new TimeComponents(23, 11, 20.264), TimeScalesFactory.getUTC()),
            Constants.EIGEN5C_EARTH_MU);
    double mass = 4093.0;
    AbsoluteDate t0 = new AbsoluteDate(new DateComponents(2003, 9, 16), new TimeComponents(23, 14, 40.264),
            TimeScalesFactory.getUTC());
    Vector3D dV = new Vector3D(0.0, 3.0, 0.0);
    double f = 40.0;
    double isp = 300.0;
    double vExhaust = Constants.G0_STANDARD_GRAVITY * isp;
    double dt = -(mass * vExhaust / f) * FastMath.expm1(-dV.getNorm() / vExhaust);
    // setup a specific coefficient file for gravity potential as it will also
    // try to read a corrupted one otherwise
    GravityFieldFactory.addPotentialCoefficientsReader(new ICGEMFormatReader("g007_eigen_05c_coef", false));
    NormalizedSphericalHarmonicsProvider gravityField = GravityFieldFactory.getNormalizedProvider(8, 8);
    BoundedPropagator withoutManeuver = getEphemeris(leo, mass, 10, new LofOffset(leo.getFrame(), LOFType.VNC),
            t0, Vector3D.ZERO, f, isp, true, true, gravityField);
    BoundedPropagator withManeuver = getEphemeris(leo, mass, 10, new LofOffset(leo.getFrame(), LOFType.VNC), t0,
            dV, f, isp, true, true, gravityField);

    // we set up a model that reverts the maneuvers
    AdapterPropagator adapterPropagator = new AdapterPropagator(withManeuver);
    SpacecraftState state0 = adapterPropagator.propagate(t0);
    AdapterPropagator.DifferentialEffect directEffect = new SmallManeuverAnalyticalModel(state0, dV.negate(),
            isp);//  www  .  ja  v a2  s . co  m
    AdapterPropagator.DifferentialEffect derivedEffect = new J2DifferentialEffect(state0, directEffect, false,
            GravityFieldFactory.getUnnormalizedProvider(gravityField));
    adapterPropagator.addEffect(directEffect);
    adapterPropagator.addEffect(derivedEffect);
    adapterPropagator.addAdditionalStateProvider(new AdditionalStateProvider() {
        public String getName() {
            return "dummy 3";
        }

        public double[] getAdditionalState(SpacecraftState state) {
            return new double[3];
        }
    });

    // the adapted propagators do not manage the additional states from the reference,
    // they simply forward them
    Assert.assertFalse(adapterPropagator.isAdditionalStateManaged("dummy 1"));
    Assert.assertFalse(adapterPropagator.isAdditionalStateManaged("dummy 2"));
    Assert.assertTrue(adapterPropagator.isAdditionalStateManaged("dummy 3"));

    double maxDelta = 0;
    double maxNominal = 0;
    for (AbsoluteDate t = t0.shiftedBy(0.5 * dt); t.compareTo(withoutManeuver.getMaxDate()) < 0; t = t
            .shiftedBy(600.0)) {
        PVCoordinates pvWithout = withoutManeuver.getPVCoordinates(t, leo.getFrame());
        PVCoordinates pvWith = withManeuver.getPVCoordinates(t, leo.getFrame());
        PVCoordinates pvReverted = adapterPropagator.getPVCoordinates(t, leo.getFrame());
        double nominal = new PVCoordinates(pvWithout, pvWith).getPosition().getNorm();
        double revertError = new PVCoordinates(pvWithout, pvReverted).getPosition().getNorm();
        maxDelta = FastMath.max(maxDelta, revertError);
        maxNominal = FastMath.max(maxNominal, nominal);
        Assert.assertEquals(2, adapterPropagator.propagate(t).getAdditionalState("dummy 1").length);
        Assert.assertEquals(1, adapterPropagator.propagate(t).getAdditionalState("dummy 2").length);
        Assert.assertEquals(3, adapterPropagator.propagate(t).getAdditionalState("dummy 3").length);
    }
    Assert.assertTrue(maxDelta < 120);
    Assert.assertTrue(maxNominal > 2800);

}

From source file:org.orekit.propagation.numerical.Jacobianizer.java

/** Compute acceleration.
 * @param retriever acceleration retriever to use for storing acceleration
 * @param date current date/*from   w  ww  .ja  v  a2 s. c  o  m*/
 * @param frame inertial reference frame for state (both orbit and attitude)
 * @param position position of spacecraft in reference frame
 * @param velocity velocity of spacecraft in reference frame
 * @param rotation orientation (attitude) of the spacecraft with respect to reference frame
 * @param mass spacecraft mass
 * @exception OrekitException if the underlying force models cannot compute the acceleration
 */
private void computeShiftedAcceleration(final AccelerationRetriever retriever, final AbsoluteDate date,
        final Frame frame, final Vector3D position, final Vector3D velocity, final Rotation rotation,
        final double mass) throws OrekitException {
    final Orbit shiftedORbit = new CartesianOrbit(new PVCoordinates(position, velocity), frame, date, mu);
    retriever.setOrbit(shiftedORbit);
    forceModel.addContribution(new SpacecraftState(shiftedORbit,
            new Attitude(date, frame, rotation, Vector3D.ZERO, Vector3D.ZERO), mass), retriever);
}

From source file:org.orekit.propagation.SpacecraftStateTest.java

@Test(expected = IllegalArgumentException.class)
public void testFramesConsistency() throws OrekitException {
    new SpacecraftState(orbit, new Attitude(orbit.getDate(), FramesFactory.getGCRF(), Rotation.IDENTITY,
            Vector3D.ZERO, Vector3D.ZERO));
}

From source file:org.orekit.utils.AngularCoordinates.java

/** Simple constructor.
 * <p> Sets the Coordinates to default : Identity,  = (0 0 0), d/dt = (0 0 0).</p>
 *///  w w w.ja  va2s.c  o  m
public AngularCoordinates() {
    this(Rotation.IDENTITY, Vector3D.ZERO, Vector3D.ZERO);
}

From source file:org.orekit.utils.AngularCoordinates.java

/** Builds a rotation/rotation rate pair.
 * @param rotation rotation//from   ww  w . j  av  a  2 s  . c o  m
 * @param rotationRate rotation rate  (rad/s)
 */
public AngularCoordinates(final Rotation rotation, final Vector3D rotationRate) {
    this(rotation, rotationRate, Vector3D.ZERO);
}

From source file:org.orekit.utils.AngularCoordinates.java

/** Builds a AngularCoordinates from  a {@link FieldRotation}&lt;{@link DerivativeStructure}&gt;.
 * <p>/*ww  w .j ava2 s  . co m*/
 * The rotation components must have time as their only derivation parameter and
 * have consistent derivation orders.
 * </p>
 * @param r rotation with time-derivatives embedded within the coordinates
 */
public AngularCoordinates(final FieldRotation<DerivativeStructure> r) {

    final double q0 = r.getQ0().getReal();
    final double q1 = r.getQ1().getReal();
    final double q2 = r.getQ2().getReal();
    final double q3 = r.getQ3().getReal();

    rotation = new Rotation(q0, q1, q2, q3, false);
    if (r.getQ0().getOrder() >= 1) {
        final double q0Dot = r.getQ0().getPartialDerivative(1);
        final double q1Dot = r.getQ1().getPartialDerivative(1);
        final double q2Dot = r.getQ2().getPartialDerivative(1);
        final double q3Dot = r.getQ3().getPartialDerivative(1);
        rotationRate = new Vector3D(
                2 * MathArrays.linearCombination(-q1, q0Dot, q0, q1Dot, q3, q2Dot, -q2, q3Dot),
                2 * MathArrays.linearCombination(-q2, q0Dot, -q3, q1Dot, q0, q2Dot, q1, q3Dot),
                2 * MathArrays.linearCombination(-q3, q0Dot, q2, q1Dot, -q1, q2Dot, q0, q3Dot));
        if (r.getQ0().getOrder() >= 2) {
            final double q0DotDot = r.getQ0().getPartialDerivative(2);
            final double q1DotDot = r.getQ1().getPartialDerivative(2);
            final double q2DotDot = r.getQ2().getPartialDerivative(2);
            final double q3DotDot = r.getQ3().getPartialDerivative(2);
            rotationAcceleration = new Vector3D(
                    2 * MathArrays.linearCombination(-q1, q0DotDot, q0, q1DotDot, q3, q2DotDot, -q2, q3DotDot),
                    2 * MathArrays.linearCombination(-q2, q0DotDot, -q3, q1DotDot, q0, q2DotDot, q1, q3DotDot),
                    2 * MathArrays.linearCombination(-q3, q0DotDot, q2, q1DotDot, -q1, q2DotDot, q0, q3DotDot));
        } else {
            rotationAcceleration = Vector3D.ZERO;
        }
    } else {
        rotationRate = Vector3D.ZERO;
        rotationAcceleration = Vector3D.ZERO;
    }

}

From source file:org.orekit.utils.AngularCoordinates.java

/** Find a vector from two known cross products.
 * <p>//from   w  ww.ja  va  2  s  . c  o m
 * We want to find  such that:   v? = c? and   v = c
 * </p>
 * <p>
 * The first equation (  v? = c?) will always be fulfilled exactly,
 * and the second one will be fulfilled if possible.
 * </p>
 * @param v1 vector forming the first known cross product
 * @param c1 know vector for cross product   v?
 * @param v2 vector forming the second known cross product
 * @param c2 know vector for cross product   v
 * @param tolerance relative tolerance factor used to check singularities
 * @return vector  such that:   v? = c? and   v = c
 * @exception MathIllegalArgumentException if vectors are inconsistent and
 * no solution can be found
 */
private static Vector3D inverseCrossProducts(final Vector3D v1, final Vector3D c1, final Vector3D v2,
        final Vector3D c2, final double tolerance) throws MathIllegalArgumentException {

    final double v12 = v1.getNormSq();
    final double v1n = FastMath.sqrt(v12);
    final double v22 = v2.getNormSq();
    final double v2n = FastMath.sqrt(v22);
    final double threshold = tolerance * FastMath.max(v1n, v2n);

    Vector3D omega;

    try {
        // create the over-determined linear system representing the two cross products
        final RealMatrix m = MatrixUtils.createRealMatrix(6, 3);
        m.setEntry(0, 1, v1.getZ());
        m.setEntry(0, 2, -v1.getY());
        m.setEntry(1, 0, -v1.getZ());
        m.setEntry(1, 2, v1.getX());
        m.setEntry(2, 0, v1.getY());
        m.setEntry(2, 1, -v1.getX());
        m.setEntry(3, 1, v2.getZ());
        m.setEntry(3, 2, -v2.getY());
        m.setEntry(4, 0, -v2.getZ());
        m.setEntry(4, 2, v2.getX());
        m.setEntry(5, 0, v2.getY());
        m.setEntry(5, 1, -v2.getX());

        final RealVector rhs = MatrixUtils.createRealVector(
                new double[] { c1.getX(), c1.getY(), c1.getZ(), c2.getX(), c2.getY(), c2.getZ() });

        // find the best solution we can
        final DecompositionSolver solver = new QRDecomposition(m, threshold).getSolver();
        final RealVector v = solver.solve(rhs);
        omega = new Vector3D(v.getEntry(0), v.getEntry(1), v.getEntry(2));

    } catch (SingularMatrixException sme) {

        // handle some special cases for which we can compute a solution
        final double c12 = c1.getNormSq();
        final double c1n = FastMath.sqrt(c12);
        final double c22 = c2.getNormSq();
        final double c2n = FastMath.sqrt(c22);

        if (c1n <= threshold && c2n <= threshold) {
            // simple special case, velocities are cancelled
            return Vector3D.ZERO;
        } else if (v1n <= threshold && c1n >= threshold) {
            // this is inconsistent, if v? is zero, c? must be 0 too
            throw new NumberIsTooLargeException(c1n, 0, true);
        } else if (v2n <= threshold && c2n >= threshold) {
            // this is inconsistent, if v is zero, c must be 0 too
            throw new NumberIsTooLargeException(c2n, 0, true);
        } else if (Vector3D.crossProduct(v1, v2).getNorm() <= threshold && v12 > threshold) {
            // simple special case, v is redundant with v?, we just ignore it
            // use the simplest : orthogonal to both v? and c?
            omega = new Vector3D(1.0 / v12, Vector3D.crossProduct(v1, c1));
        } else {
            throw sme;
        }

    }

    // check results
    final double d1 = Vector3D.distance(Vector3D.crossProduct(omega, v1), c1);
    if (d1 > threshold) {
        throw new NumberIsTooLargeException(d1, 0, true);
    }

    final double d2 = Vector3D.distance(Vector3D.crossProduct(omega, v2), c2);
    if (d2 > threshold) {
        throw new NumberIsTooLargeException(d2, 0, true);
    }

    return omega;

}

From source file:org.orekit.utils.AngularCoordinatesTest.java

@Test
public void testZeroRate() throws OrekitException {
    AngularCoordinates ac = new AngularCoordinates(new Rotation(0.48, 0.64, 0.36, 0.48, false), Vector3D.ZERO,
            Vector3D.ZERO);/*from w  w w .  j av a  2  s  . c  o  m*/
    Assert.assertEquals(Vector3D.ZERO, ac.getRotationRate());
    double dt = 10.0;
    AngularCoordinates shifted = ac.shiftedBy(dt);
    Assert.assertEquals(Vector3D.ZERO, shifted.getRotationAcceleration());
    Assert.assertEquals(Vector3D.ZERO, shifted.getRotationRate());
    Assert.assertEquals(0.0, Rotation.distance(ac.getRotation(), shifted.getRotation()), 1.0e-15);
}

From source file:org.orekit.utils.AngularCoordinatesTest.java

@Test
public void testShiftWithoutAcceleration() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    AngularCoordinates ac = new AngularCoordinates(Rotation.IDENTITY, new Vector3D(rate, Vector3D.PLUS_K),
            Vector3D.ZERO);
    Assert.assertEquals(rate, ac.getRotationRate().getNorm(), 1.0e-10);
    double dt = 10.0;
    double alpha = rate * dt;
    AngularCoordinates shifted = ac.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getRotationRate().getNorm(), 1.0e-10);
    Assert.assertEquals(alpha, Rotation.distance(ac.getRotation(), shifted.getRotation()), 1.0e-15);

    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-15);/*from w w w  . 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-15);
    Vector3D zSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K);
    Assert.assertEquals(0.0, zSat.subtract(Vector3D.PLUS_K).getNorm(), 1.0e-15);

}

From source file:org.orekit.utils.AngularCoordinatesTest.java

@Test
public void testShiftWithAcceleration() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    double acc = 0.001;
    double dt = 1.0;
    int n = 2000;
    final AngularCoordinates quadratic = new AngularCoordinates(Rotation.IDENTITY,
            new Vector3D(rate, Vector3D.PLUS_K), new Vector3D(acc, Vector3D.PLUS_J));
    final AngularCoordinates linear = new AngularCoordinates(quadratic.getRotation(),
            quadratic.getRotationRate(), Vector3D.ZERO);

    final FirstOrderDifferentialEquations ode = new FirstOrderDifferentialEquations() {
        public int getDimension() {
            return 4;
        }//from   ww w  .java2s  .  c  om

        public void computeDerivatives(final double t, final double[] q, final double[] qDot) {
            final double omegaX = quadratic.getRotationRate().getX()
                    + t * quadratic.getRotationAcceleration().getX();
            final double omegaY = quadratic.getRotationRate().getY()
                    + t * quadratic.getRotationAcceleration().getY();
            final double omegaZ = quadratic.getRotationRate().getZ()
                    + t * quadratic.getRotationAcceleration().getZ();
            qDot[0] = 0.5 * MathArrays.linearCombination(-q[1], omegaX, -q[2], omegaY, -q[3], omegaZ);
            qDot[1] = 0.5 * MathArrays.linearCombination(q[0], omegaX, -q[3], omegaY, q[2], omegaZ);
            qDot[2] = 0.5 * MathArrays.linearCombination(q[3], omegaX, q[0], omegaY, -q[1], omegaZ);
            qDot[3] = 0.5 * MathArrays.linearCombination(-q[2], omegaX, q[1], omegaY, q[0], omegaZ);
        }
    };
    FirstOrderIntegrator integrator = new DormandPrince853Integrator(1.0e-6, 1.0, 1.0e-12, 1.0e-12);
    integrator.addStepHandler(new StepNormalizer(dt / n, new FixedStepHandler() {
        public void init(double t0, double[] y0, double t) {
        }

        public void handleStep(double t, double[] y, double[] yDot, boolean isLast) {
            Rotation reference = new Rotation(y[0], y[1], y[2], y[3], true);

            // the error in shiftedBy taking acceleration into account is cubic
            double expectedCubicError = 1.4544e-6 * t * t * t;
            Assert.assertEquals(expectedCubicError,
                    Rotation.distance(reference, quadratic.shiftedBy(t).getRotation()),
                    0.0001 * expectedCubicError);

            // the error in shiftedBy not taking acceleration into account is quadratic
            double expectedQuadraticError = 5.0e-4 * t * t;
            Assert.assertEquals(expectedQuadraticError,
                    Rotation.distance(reference, linear.shiftedBy(t).getRotation()),
                    0.00001 * expectedQuadraticError);

        }
    }));

    double[] y = new double[] { quadratic.getRotation().getQ0(), quadratic.getRotation().getQ1(),
            quadratic.getRotation().getQ2(), quadratic.getRotation().getQ3() };
    integrator.integrate(ode, 0, y, dt, y);

}