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.forces.gravity.CunninghamAttractionModelTest.java

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

    Utils.setDataRoot("regular-data:potential/grgs-format");
    GravityFieldFactory.addPotentialCoefficientsReader(new GRGSFormatReader("grim4s4_gr", true));

    // pos-vel (from a ZOOM ephemeris reference)
    final Vector3D pos = new Vector3D(6.46885878304673824e+06, -1.88050918456274318e+06,
            -1.32931592294715829e+04);/*from   ww w.  j a v a 2 s .c om*/
    final Vector3D vel = new Vector3D(2.14718074509906819e+03, 7.38239351251748485e+03,
            -1.14097953925384523e+01);
    final SpacecraftState spacecraftState = new SpacecraftState(new CartesianOrbit(new PVCoordinates(pos, vel),
            FramesFactory.getGCRF(), new AbsoluteDate(2005, 3, 5, 0, 24, 0.0, TimeScalesFactory.getTAI()),
            GravityFieldFactory.getUnnormalizedProvider(1, 1).getMu()));

    AccelerationRetriever accelerationRetriever = new AccelerationRetriever();
    for (int i = 2; i <= 69; i++) {
        // perturbing force (ITRF2008 central body frame)
        final ForceModel cunModel = new CunninghamAttractionModel(
                FramesFactory.getITRF(IERSConventions.IERS_2010, true),
                GravityFieldFactory.getUnnormalizedProvider(i, i));
        final ForceModel droModel = new DrozinerAttractionModel(
                FramesFactory.getITRF(IERSConventions.IERS_2010, true),
                GravityFieldFactory.getUnnormalizedProvider(i, i));

        /**
         * Compute acceleration
         */
        cunModel.addContribution(spacecraftState, accelerationRetriever);
        final Vector3D cunGamma = accelerationRetriever.getAcceleration();
        droModel.addContribution(spacecraftState, accelerationRetriever);
        final Vector3D droGamma = accelerationRetriever.getAcceleration();
        Assert.assertEquals(0.0, cunGamma.subtract(droGamma).getNorm(), 2.2e-9 * droGamma.getNorm());

    }

}

From source file:org.orekit.forces.gravity.HolmesFeatherstoneAttractionModelTest.java

private double accelerationRelativeError(ForceModel testModel, ForceModel referenceModel, SpacecraftState state)
        throws OrekitException {

    AccelerationRetriever accelerationRetriever = new AccelerationRetriever();
    testModel.addContribution(state, accelerationRetriever);
    final Vector3D testAcceleration = accelerationRetriever.getAcceleration();
    referenceModel.addContribution(state, accelerationRetriever);
    final Vector3D referenceAcceleration = accelerationRetriever.getAcceleration();

    return testAcceleration.subtract(referenceAcceleration).getNorm() / referenceAcceleration.getNorm();

}

From source file:org.orekit.forces.gravity.ThirdBodyAttraction.java

/** {@inheritDoc} */
public void addContribution(final SpacecraftState s, final TimeDerivativesEquations adder)
        throws OrekitException {

    // compute bodies separation vectors and squared norm
    final Vector3D centralToBody = body.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
    final double r2Central = centralToBody.getNormSq();
    final Vector3D satToBody = centralToBody.subtract(s.getPVCoordinates().getPosition());
    final double r2Sat = satToBody.getNormSq();

    // compute relative acceleration
    final Vector3D gamma = new Vector3D(gm / (r2Sat * FastMath.sqrt(r2Sat)), satToBody,
            -gm / (r2Central * FastMath.sqrt(r2Central)), centralToBody);

    // add contribution to the ODE second member
    adder.addXYZAcceleration(gamma.getX(), gamma.getY(), gamma.getZ());

}

From source file:org.orekit.forces.gravity.ThirdBodyAttraction.java

/** {@inheritDoc} */
public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s,
        final String paramName) throws OrekitException {

    complainIfNotSupported(paramName);// www  . j  a  va 2 s. c  o m

    // compute bodies separation vectors and squared norm
    final Vector3D centralToBody = body.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
    final double r2Central = centralToBody.getNormSq();
    final Vector3D satToBody = centralToBody.subtract(s.getPVCoordinates().getPosition());
    final double r2Sat = satToBody.getNormSq();

    final DerivativeStructure gmds = new DerivativeStructure(1, 1, 0, gm);

    // compute relative acceleration
    return new FieldVector3D<DerivativeStructure>(gmds.divide(r2Sat * FastMath.sqrt(r2Sat)), satToBody,
            gmds.divide(-r2Central * FastMath.sqrt(r2Central)), centralToBody);

}

From source file:org.orekit.forces.radiation.SolarRadiationPressure.java

/** {@inheritDoc} */
public void addContribution(final SpacecraftState s, final TimeDerivativesEquations adder)
        throws OrekitException {

    final AbsoluteDate date = s.getDate();
    final Frame frame = s.getFrame();
    final Vector3D position = s.getPVCoordinates().getPosition();
    final Vector3D sunSatVector = position.subtract(sun.getPVCoordinates(date, frame).getPosition());
    final double r2 = sunSatVector.getNormSq();

    // compute flux
    final double rawP = kRef * getLightningRatio(position, frame, date) / r2;
    final Vector3D flux = new Vector3D(rawP / FastMath.sqrt(r2), sunSatVector);

    final Vector3D acceleration = spacecraft.radiationPressureAcceleration(date, frame, position,
            s.getAttitude().getRotation(), s.getMass(), flux);

    // provide the perturbing acceleration to the derivatives adder
    adder.addAcceleration(acceleration, s.getFrame());

}

From source file:org.orekit.forces.radiation.SolarRadiationPressure.java

/** {@inheritDoc} */
public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s,
        final String paramName) throws OrekitException {

    complainIfNotSupported(paramName);//from  www .j a va  2  s .  c om
    final AbsoluteDate date = s.getDate();
    final Frame frame = s.getFrame();
    final Vector3D position = s.getPVCoordinates().getPosition();
    final Vector3D sunSatVector = position.subtract(sun.getPVCoordinates(date, frame).getPosition());
    final double r2 = sunSatVector.getNormSq();

    // compute flux
    final double rawP = kRef * getLightningRatio(position, frame, date) / r2;
    final Vector3D flux = new Vector3D(rawP / FastMath.sqrt(r2), sunSatVector);

    return spacecraft.radiationPressureAcceleration(date, frame, position, s.getAttitude().getRotation(),
            s.getMass(), flux, paramName);

}

From source file:org.orekit.forces.SphericalSpacecraftTest.java

@Test
public void testDrag() throws OrekitException {
    AbsoluteDate date = new AbsoluteDate(new DateComponents(2008, 04, 07), TimeComponents.H00,
            TimeScalesFactory.getTAI());

    // Satellite position as circular parameters
    final double mu = 3.9860047e14;
    final double raan = 270.;
    Orbit circ = new CircularOrbit(7178000.0, 0.5e-4, -0.5e-4, FastMath.toRadians(50.),
            FastMath.toRadians(raan), FastMath.toRadians(5.300 - raan), PositionAngle.MEAN,
            FramesFactory.getEME2000(), date, mu);

    SpacecraftState state = new SpacecraftState(circ);
    double surface = 5.0;
    double cd = 2.0;
    SphericalSpacecraft s = new SphericalSpacecraft(surface, cd, 0.0, 0.0);
    Vector3D relativeVelocity = new Vector3D(36.0, 48.0, 80.0);

    double rho = 0.001;
    Vector3D computedAcceleration = s.dragAcceleration(state.getDate(), state.getFrame(),
            state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(), rho,
            relativeVelocity);// w  w w  .  j ava  2  s  .  c  o  m
    Vector3D d = relativeVelocity.normalize();
    double v2 = relativeVelocity.getNormSq();
    Vector3D expectedAcceleration = new Vector3D(rho * surface * cd * v2 / (2 * state.getMass()), d);
    Assert.assertEquals(0.0, computedAcceleration.subtract(expectedAcceleration).getNorm(), 1.0e-15);

}

From source file:org.orekit.forces.SphericalSpacecraftTest.java

@Test
public void testRadiationPressure() throws OrekitException {
    AbsoluteDate date = new AbsoluteDate(new DateComponents(2008, 04, 07), TimeComponents.H00,
            TimeScalesFactory.getTAI());

    // Satellite position as circular parameters
    final double mu = 3.9860047e14;
    final double raan = 270.;
    Orbit circ = new CircularOrbit(7178000.0, 0.5e-4, -0.5e-4, FastMath.toRadians(50.),
            FastMath.toRadians(raan), FastMath.toRadians(5.300 - raan), PositionAngle.MEAN,
            FramesFactory.getEME2000(), date, mu);

    SpacecraftState state = new SpacecraftState(circ);
    double surface = 5.0;
    double kA = 0.9;
    double kR = 0.1;
    SphericalSpacecraft s = new SphericalSpacecraft(surface, 0.0, kA, kR);
    Vector3D flux = new Vector3D(36.0, 48.0, 80.0);

    Vector3D computedAcceleration = s.radiationPressureAcceleration(state.getDate(), state.getFrame(),
            state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(), flux);
    Vector3D d = flux.normalize();
    double f = flux.getNorm();
    double p = (1 - kA) * (1 - kR);
    Vector3D expectedAcceleration = new Vector3D(surface * f * (1 + 4 * p / 9) / state.getMass(), d);
    Assert.assertEquals(0.0, computedAcceleration.subtract(expectedAcceleration).getNorm(), 1.0e-15);

}

From source file:org.orekit.frames.FrameTest.java

private void checkNoTransform(Transform transform, Random random) {
    for (int i = 0; i < 100; ++i) {
        Vector3D a = new Vector3D(random.nextDouble(), random.nextDouble(), random.nextDouble());
        Vector3D b = transform.transformVector(a);
        Assert.assertEquals(0, a.subtract(b).getNorm(), 1.0e-10);
        Vector3D c = transform.transformPosition(a);
        Assert.assertEquals(0, a.subtract(c).getNorm(), 1.0e-10);
    }/*from   ww w  .  ja  v a2s  . co m*/
}

From source file:org.orekit.frames.HelmertTransformationTest.java

@Test
public void testHelmert20052008() throws OrekitException {
    Frame itrf2008 = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
    Frame itrf2005 = HelmertTransformation.Predefined.ITRF_2008_TO_ITRF_2005.createTransformedITRF(itrf2008,
            "2005");
    Vector3D pos2005 = new Vector3D(1234567.8, 2345678.9, 3456789.0);

    // check the Helmert transformation as per http://itrf.ign.fr/ITRF_solutions/2008/tp_08-05.php
    AbsoluteDate date = new AbsoluteDate(2005, 1, 1, 12, 0, 0, TimeScalesFactory.getTT());
    Vector3D pos2008 = itrf2005.getTransformTo(itrf2008, date).transformPosition(pos2005);
    Vector3D generalOffset = pos2005.subtract(pos2008);
    Vector3D linearOffset = computeOffsetLinearly(-0.5, -0.9, -4.7, 0.000, 0.000, 0.000, 0.3, 0.0, 0.0, 0.000,
            0.000, 0.000, pos2005, 0.0);
    Vector3D error = generalOffset.subtract(linearOffset);
    Assert.assertEquals(0.0, error.getNorm(), 2.0e-13 * pos2005.getNorm());

    date = date.shiftedBy(Constants.JULIAN_YEAR);
    pos2008 = itrf2005.getTransformTo(itrf2008, date).transformPosition(pos2005);
    generalOffset = pos2005.subtract(pos2008);
    linearOffset = computeOffsetLinearly(-0.5, -0.9, -4.7, 0.000, 0.000, 0.000, 0.3, 0.0, 0.0, 0.000, 0.000,
            0.000, pos2005, 1.0);/* w  ww  . j av  a 2 s . co m*/
    error = generalOffset.subtract(linearOffset);
    Assert.assertEquals(0.0, error.getNorm(), 2.0e-13 * pos2005.getNorm());

}