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

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

Introduction

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

Prototype

public Vector3D subtract(final Vector<Euclidean3D> v) 

Source Link

Usage

From source file:org.orekit.models.earth.tessellation.EllipsoidTessellator.java

/** Estimate an approximate motion in the along direction.
 * @param start node at start of motion//from  w w w .  jav a  2 s  .  co  m
 * @param end desired point at end of motion
 * @return approximate motion in the along direction
 */
private double estimateAlongMotion(final Mesh.Node start, final Vector3D end) {
    return Vector3D.dotProduct(start.getAlong(), end.subtract(start.getV()));
}

From source file:org.orekit.models.earth.tessellation.EllipsoidTessellator.java

/** Estimate an approximate motion in the across direction.
 * @param start node at start of motion/*from w w  w  .j  a  v  a 2  s .com*/
 * @param end desired point at end of motion
 * @return approximate motion in the across direction
 */
private double estimateAcrossMotion(final Mesh.Node start, final Vector3D end) {
    return Vector3D.dotProduct(start.getAcross(), end.subtract(start.getV()));
}

From source file:org.orekit.orbits.CartesianParametersTest.java

private void testShift(CartesianOrbit tested, Orbit reference, double threshold) {
    for (double dt = -1000; dt < 1000; dt += 10.0) {

        PVCoordinates pvTested = tested.shiftedBy(dt).getPVCoordinates();
        Vector3D pTested = pvTested.getPosition();
        Vector3D vTested = pvTested.getVelocity();

        PVCoordinates pvReference = reference.shiftedBy(dt).getPVCoordinates();
        Vector3D pReference = pvReference.getPosition();
        Vector3D vReference = pvReference.getVelocity();

        Assert.assertEquals(0, pTested.subtract(pReference).getNorm(), threshold * pReference.getNorm());
        Assert.assertEquals(0, vTested.subtract(vReference).getNorm(), threshold * vReference.getNorm());

    }//  w ww  . j a  v  a 2s. c om
}

From source file:org.orekit.orbits.CircularParametersTest.java

@Test
public void testSymmetryEll() {

    // elliptic and non equatorail orbit
    Vector3D position = new Vector3D(4512.9, 18260., -5127.);
    Vector3D velocity = new Vector3D(134664.6, 90066.8, 72047.6);
    PVCoordinates pvCoordinates = new PVCoordinates(position, velocity);

    CircularOrbit p = new CircularOrbit(pvCoordinates, FramesFactory.getEME2000(), date, mu);

    Vector3D positionOffset = p.getPVCoordinates().getPosition();
    Vector3D velocityOffset = p.getPVCoordinates().getVelocity();

    positionOffset = positionOffset.subtract(position);
    velocityOffset = velocityOffset.subtract(velocity);

    Assert.assertEquals(0.0, positionOffset.getNorm(), position.getNorm() * Utils.epsilonTest);
    Assert.assertEquals(0.0, velocityOffset.getNorm(), velocity.getNorm() * Utils.epsilonTest);

}

From source file:org.orekit.orbits.CircularParametersTest.java

@Test
public void testInterpolation() throws OrekitException {

    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);// www . jav  a2s  .  com

    // set up a 5 points sample
    List<Orbit> sample = new ArrayList<Orbit>();
    for (double dt = 0; dt < 300.0; dt += 60.0) {
        sample.add(propagator.propagate(date.shiftedBy(dt)).getOrbit());
    }

    // well inside the sample, interpolation should be much better than Keplerian shift
    double maxShiftError = 0;
    double maxInterpolationError = 0;
    for (double dt = 0; dt < 241.0; dt += 1.0) {
        AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt);
        Vector3D shifted = initialOrbit.shiftedBy(dt).getPVCoordinates().getPosition();
        Vector3D interpolated = initialOrbit.interpolate(t, sample).getPVCoordinates().getPosition();
        Vector3D propagated = propagator.propagate(t).getPVCoordinates().getPosition();
        maxShiftError = FastMath.max(maxShiftError, shifted.subtract(propagated).getNorm());
        maxInterpolationError = FastMath.max(maxInterpolationError,
                interpolated.subtract(propagated).getNorm());
    }
    Assert.assertTrue(maxShiftError > 390.0);
    Assert.assertTrue(maxInterpolationError < 0.04);

    // slightly past sample end, interpolation should quickly increase, but remain reasonable
    maxShiftError = 0;
    maxInterpolationError = 0;
    for (double dt = 240; dt < 300.0; dt += 1.0) {
        AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt);
        Vector3D shifted = initialOrbit.shiftedBy(dt).getPVCoordinates().getPosition();
        Vector3D interpolated = initialOrbit.interpolate(t, sample).getPVCoordinates().getPosition();
        Vector3D propagated = propagator.propagate(t).getPVCoordinates().getPosition();
        maxShiftError = FastMath.max(maxShiftError, shifted.subtract(propagated).getNorm());
        maxInterpolationError = FastMath.max(maxInterpolationError,
                interpolated.subtract(propagated).getNorm());
    }
    Assert.assertTrue(maxShiftError < 610.0);
    Assert.assertTrue(maxInterpolationError < 1.3);

    // far past sample end, interpolation should become really wrong
    // (in this test case, break even occurs at around 863 seconds, with a 3.9 km error)
    maxShiftError = 0;
    maxInterpolationError = 0;
    for (double dt = 300; dt < 1000; dt += 1.0) {
        AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt);
        Vector3D shifted = initialOrbit.shiftedBy(dt).getPVCoordinates().getPosition();
        Vector3D interpolated = initialOrbit.interpolate(t, sample).getPVCoordinates().getPosition();
        Vector3D propagated = propagator.propagate(t).getPVCoordinates().getPosition();
        maxShiftError = FastMath.max(maxShiftError, shifted.subtract(propagated).getNorm());
        maxInterpolationError = FastMath.max(maxInterpolationError,
                interpolated.subtract(propagated).getNorm());
    }
    Assert.assertTrue(maxShiftError < 5000.0);
    Assert.assertTrue(maxInterpolationError > 8800.0);

}

From source file:org.orekit.orbits.EquinoctialParametersTest.java

@Test
public void testInterpolation() throws OrekitException {

    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 EquinoctialOrbit initialOrbit = new EquinoctialOrbit(new PVCoordinates(position, velocity),
            FramesFactory.getEME2000(), date, ehMu);

    EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(initialOrbit, ae, ehMu, c20, c30, c40,
            c50, c60);/* www .  ja  v  a  2  s.co m*/

    // set up a 5 points sample
    List<Orbit> sample = new ArrayList<Orbit>();
    for (double dt = 0; dt < 300.0; dt += 60.0) {
        sample.add(propagator.propagate(date.shiftedBy(dt)).getOrbit());
    }

    // well inside the sample, interpolation should be much better than Keplerian shift
    double maxShiftError = 0;
    double maxInterpolationError = 0;
    for (double dt = 0; dt < 241.0; dt += 1.0) {
        AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt);
        Vector3D shifted = initialOrbit.shiftedBy(dt).getPVCoordinates().getPosition();
        Vector3D interpolated = initialOrbit.interpolate(t, sample).getPVCoordinates().getPosition();
        Vector3D propagated = propagator.propagate(t).getPVCoordinates().getPosition();
        maxShiftError = FastMath.max(maxShiftError, shifted.subtract(propagated).getNorm());
        maxInterpolationError = FastMath.max(maxInterpolationError,
                interpolated.subtract(propagated).getNorm());
    }
    Assert.assertTrue(maxShiftError > 390.0);
    Assert.assertTrue(maxInterpolationError < 0.04);

    // slightly past sample end, interpolation should quickly increase, but remain reasonable
    maxShiftError = 0;
    maxInterpolationError = 0;
    for (double dt = 240; dt < 300.0; dt += 1.0) {
        AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt);
        Vector3D shifted = initialOrbit.shiftedBy(dt).getPVCoordinates().getPosition();
        Vector3D interpolated = initialOrbit.interpolate(t, sample).getPVCoordinates().getPosition();
        Vector3D propagated = propagator.propagate(t).getPVCoordinates().getPosition();
        maxShiftError = FastMath.max(maxShiftError, shifted.subtract(propagated).getNorm());
        maxInterpolationError = FastMath.max(maxInterpolationError,
                interpolated.subtract(propagated).getNorm());
    }
    Assert.assertTrue(maxShiftError < 610.0);
    Assert.assertTrue(maxInterpolationError < 1.3);

    // far past sample end, interpolation should become really wrong
    // (in this test case, break even occurs at around 863 seconds, with a 3.9 km error)
    maxShiftError = 0;
    maxInterpolationError = 0;
    for (double dt = 300; dt < 1000; dt += 1.0) {
        AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt);
        Vector3D shifted = initialOrbit.shiftedBy(dt).getPVCoordinates().getPosition();
        Vector3D interpolated = initialOrbit.interpolate(t, sample).getPVCoordinates().getPosition();
        Vector3D propagated = propagator.propagate(t).getPVCoordinates().getPosition();
        maxShiftError = FastMath.max(maxShiftError, shifted.subtract(propagated).getNorm());
        maxInterpolationError = FastMath.max(maxInterpolationError,
                interpolated.subtract(propagated).getNorm());
    }
    Assert.assertTrue(maxShiftError < 5000.0);
    Assert.assertTrue(maxInterpolationError > 8800.0);

}

From source file:org.orekit.orbits.KeplerianParametersTest.java

@Test
public void testVeryLargeEccentricity() {

    final Frame eme2000 = FramesFactory.getEME2000();
    final double meanAnomaly = 1.;
    final KeplerianOrbit orb0 = new KeplerianOrbit(42600e3, 0.9, 0.00001, 0, 0, FastMath.toRadians(meanAnomaly),
            PositionAngle.MEAN, eme2000, date, mu);

    // big dV along Y
    final Vector3D deltaV = new Vector3D(0.0, 110000.0, 0.0);
    final PVCoordinates pv1 = new PVCoordinates(orb0.getPVCoordinates().getPosition(),
            orb0.getPVCoordinates().getVelocity().add(deltaV));
    final KeplerianOrbit orb1 = new KeplerianOrbit(pv1, eme2000, date, mu);

    // Despite large eccentricity, the conversion of mean anomaly to hyperbolic eccentric anomaly
    // converges in less than 50 iterations (issue #114)
    final PVCoordinates pvTested = orb1.shiftedBy(0).getPVCoordinates();
    final Vector3D pTested = pvTested.getPosition();
    final Vector3D vTested = pvTested.getVelocity();

    final PVCoordinates pvReference = orb1.getPVCoordinates();
    final Vector3D pReference = pvReference.getPosition();
    final Vector3D vReference = pvReference.getVelocity();

    final double threshold = 1.e-15;
    Assert.assertEquals(0, pTested.subtract(pReference).getNorm(), threshold * pReference.getNorm());
    Assert.assertEquals(0, vTested.subtract(vReference).getNorm(), threshold * vReference.getNorm());

}

From source file:org.orekit.orbits.KeplerianParametersTest.java

@Test
public void testInterpolation() throws OrekitException {

    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 KeplerianOrbit initialOrbit = new KeplerianOrbit(new PVCoordinates(position, velocity),
            FramesFactory.getEME2000(), date, ehMu);

    EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(initialOrbit, ae, ehMu, c20, c30, c40,
            c50, c60);// www . j ava2  s  . c  om

    // set up a 5 points sample
    List<Orbit> sample = new ArrayList<Orbit>();
    for (double dt = 0; dt < 300.0; dt += 60.0) {
        sample.add(propagator.propagate(date.shiftedBy(dt)).getOrbit());
    }

    // well inside the sample, interpolation should be slightly better than Keplerian shift
    // the relative bad behaviour here is due to eccentricity, which cannot be
    // accurately interpolated with a polynomial in this case
    double maxShiftPositionError = 0;
    double maxInterpolationPositionError = 0;
    double maxShiftEccentricityError = 0;
    double maxInterpolationEccentricityError = 0;
    for (double dt = 0; dt < 241.0; dt += 1.0) {
        AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt);
        Vector3D shiftedP = initialOrbit.shiftedBy(dt).getPVCoordinates().getPosition();
        Vector3D interpolatedP = initialOrbit.interpolate(t, sample).getPVCoordinates().getPosition();
        Vector3D propagatedP = propagator.propagate(t).getPVCoordinates().getPosition();
        double shiftedE = initialOrbit.shiftedBy(dt).getE();
        double interpolatedE = initialOrbit.interpolate(t, sample).getE();
        double propagatedE = propagator.propagate(t).getE();
        maxShiftPositionError = FastMath.max(maxShiftPositionError, shiftedP.subtract(propagatedP).getNorm());
        maxInterpolationPositionError = FastMath.max(maxInterpolationPositionError,
                interpolatedP.subtract(propagatedP).getNorm());
        maxShiftEccentricityError = FastMath.max(maxShiftEccentricityError,
                FastMath.abs(shiftedE - propagatedE));
        maxInterpolationEccentricityError = FastMath.max(maxInterpolationEccentricityError,
                FastMath.abs(interpolatedE - propagatedE));
    }
    Assert.assertTrue(maxShiftPositionError > 390.0);
    Assert.assertTrue(maxInterpolationPositionError < 62.0);
    Assert.assertTrue(maxShiftEccentricityError > 4.5e-4);
    Assert.assertTrue(maxInterpolationEccentricityError < 2.6e-5);

    // slightly past sample end, bad eccentricity interpolation shows up
    // (in this case, interpolated eccentricity exceeds 1.0 btween 1900
    // and 1910s, while semi-majaxis remains positive, so this is not
    // even a proper hyperbolic orbit...)
    maxShiftPositionError = 0;
    maxInterpolationPositionError = 0;
    maxShiftEccentricityError = 0;
    maxInterpolationEccentricityError = 0;
    for (double dt = 240; dt < 600; dt += 1.0) {
        AbsoluteDate t = initialOrbit.getDate().shiftedBy(dt);
        Vector3D shiftedP = initialOrbit.shiftedBy(dt).getPVCoordinates().getPosition();
        Vector3D interpolatedP = initialOrbit.interpolate(t, sample).getPVCoordinates().getPosition();
        Vector3D propagatedP = propagator.propagate(t).getPVCoordinates().getPosition();
        double shiftedE = initialOrbit.shiftedBy(dt).getE();
        double interpolatedE = initialOrbit.interpolate(t, sample).getE();
        double propagatedE = propagator.propagate(t).getE();
        maxShiftPositionError = FastMath.max(maxShiftPositionError, shiftedP.subtract(propagatedP).getNorm());
        maxInterpolationPositionError = FastMath.max(maxInterpolationPositionError,
                interpolatedP.subtract(propagatedP).getNorm());
        maxShiftEccentricityError = FastMath.max(maxShiftEccentricityError,
                FastMath.abs(shiftedE - propagatedE));
        maxInterpolationEccentricityError = FastMath.max(maxInterpolationEccentricityError,
                FastMath.abs(interpolatedE - propagatedE));
    }
    Assert.assertTrue(maxShiftPositionError < 2200.0);
    Assert.assertTrue(maxInterpolationPositionError > 72000.0);
    Assert.assertTrue(maxShiftEccentricityError < 1.2e-3);
    Assert.assertTrue(maxInterpolationEccentricityError > 3.8e-3);

}

From source file:org.orekit.propagation.analytical.tle.TLETest.java

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

    BufferedReader rEntry = null;
    BufferedReader rResults = null;

    InputStream inEntry = TLETest.class.getResourceAsStream("/tle/extrapolationTest-data/SatCode-entry");
    rEntry = new BufferedReader(new InputStreamReader(inEntry));

    try {//from  ww  w  . j a  v  a2  s.  com
        InputStream inResults = TLETest.class
                .getResourceAsStream("/tle/extrapolationTest-data/SatCode-results");
        rResults = new BufferedReader(new InputStreamReader(inResults));

        try {
            double cumulated = 0; // sum of all differences between test cases and OREKIT results
            boolean stop = false;

            String rline = rResults.readLine();

            while (!stop) {
                if (rline == null)
                    break;

                String[] title = rline.split(" ");

                if (title[0].matches("r")) {

                    String eline;
                    int count = 0;
                    String[] header = new String[4];
                    for (eline = rEntry.readLine(); (eline != null)
                            && (eline.charAt(0) == '#'); eline = rEntry.readLine()) {
                        header[count++] = eline;
                    }
                    String line1 = eline;
                    String line2 = rEntry.readLine();
                    Assert.assertTrue(TLE.isFormatOK(line1, line2));

                    TLE tle = new TLE(line1, line2);

                    int satNum = Integer.parseInt(title[1]);
                    Assert.assertTrue(satNum == tle.getSatelliteNumber());
                    TLEPropagator ex = TLEPropagator.selectExtrapolator(tle);

                    for (rline = rResults.readLine(); (rline != null)
                            && (rline.charAt(0) != 'r'); rline = rResults.readLine()) {

                        String[] data = rline.split(" ");
                        double minFromStart = Double.parseDouble(data[0]);
                        double pX = 1000 * Double.parseDouble(data[1]);
                        double pY = 1000 * Double.parseDouble(data[2]);
                        double pZ = 1000 * Double.parseDouble(data[3]);
                        double vX = 1000 * Double.parseDouble(data[4]);
                        double vY = 1000 * Double.parseDouble(data[5]);
                        double vZ = 1000 * Double.parseDouble(data[6]);
                        Vector3D testPos = new Vector3D(pX, pY, pZ);
                        Vector3D testVel = new Vector3D(vX, vY, vZ);

                        AbsoluteDate date = tle.getDate().shiftedBy(minFromStart * 60);
                        PVCoordinates results = ex.getPVCoordinates(date);
                        double normDifPos = testPos.subtract(results.getPosition()).getNorm();
                        double normDifVel = testVel.subtract(results.getVelocity()).getNorm();

                        cumulated += normDifPos;
                        Assert.assertEquals(0, normDifPos, 2e-3);
                        ;
                        Assert.assertEquals(0, normDifVel, 1e-5);

                    }
                }
            }
            Assert.assertEquals(0, cumulated, 0.026);
        } finally {
            if (rResults != null) {
                rResults.close();
            }
        }
    } finally {
        if (rEntry != null) {
            rEntry.close();
        }
    }
}

From source file:org.orekit.propagation.events.EclipseDetector.java

/** Compute the value of the switching function.
 * This function becomes negative when entering the region of shadow
 * and positive when exiting./* w  w  w.ja  va 2s .  c  o m*/
 * @param s the current state information: date, kinematics, attitude
 * @return value of the switching function
 * @exception OrekitException if some specific error occurs
 */
public double g(final SpacecraftState s) throws OrekitException {
    final Vector3D pted = occulted.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
    final Vector3D ping = occulting.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
    final Vector3D psat = s.getPVCoordinates().getPosition();
    final Vector3D ps = pted.subtract(psat);
    final Vector3D po = ping.subtract(psat);
    final double angle = Vector3D.angle(ps, po);
    final double rs = FastMath.asin(occultedRadius / ps.getNorm());
    if (Double.isNaN(rs)) {
        return FastMath.PI;
    }
    final double ro = FastMath.asin(occultingRadius / po.getNorm());
    if (Double.isNaN(ro)) {
        return -FastMath.PI;
    }
    return totalEclipse ? (angle - ro + rs) : (angle - ro - rs);
}