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.propagation.integration.IntegratedEphemerisTest.java

@Test
public void testNormalKeplerIntegration() throws OrekitException {

    // Keplerian propagator definition
    KeplerianPropagator keplerEx = new KeplerianPropagator(initialOrbit);

    // Integrated ephemeris

    // Propagation
    AbsoluteDate finalDate = initialOrbit.getDate().shiftedBy(Constants.JULIAN_DAY);
    numericalPropagator.setEphemerisMode();
    numericalPropagator.setInitialState(new SpacecraftState(initialOrbit));
    numericalPropagator.propagate(finalDate);
    Assert.assertTrue(numericalPropagator.getCalls() < 3200);
    BoundedPropagator ephemeris = numericalPropagator.getGeneratedEphemeris();

    // tests/*from w w  w.  j  av a 2s.  c  om*/
    for (int i = 1; i <= Constants.JULIAN_DAY; i++) {
        AbsoluteDate intermediateDate = initialOrbit.getDate().shiftedBy(i);
        SpacecraftState keplerIntermediateOrbit = keplerEx.propagate(intermediateDate);
        SpacecraftState numericIntermediateOrbit = ephemeris.propagate(intermediateDate);
        Vector3D kepPosition = keplerIntermediateOrbit.getPVCoordinates().getPosition();
        Vector3D numPosition = numericIntermediateOrbit.getPVCoordinates().getPosition();
        Assert.assertEquals(0, kepPosition.subtract(numPosition).getNorm(), 0.06);
    }

    // test inv
    AbsoluteDate intermediateDate = initialOrbit.getDate().shiftedBy(41589);
    SpacecraftState keplerIntermediateOrbit = keplerEx.propagate(intermediateDate);
    SpacecraftState state = keplerEx.propagate(finalDate);
    numericalPropagator.setInitialState(state);
    numericalPropagator.setEphemerisMode();
    numericalPropagator.propagate(initialOrbit.getDate());
    BoundedPropagator invEphemeris = numericalPropagator.getGeneratedEphemeris();
    SpacecraftState numericIntermediateOrbit = invEphemeris.propagate(intermediateDate);
    Vector3D kepPosition = keplerIntermediateOrbit.getPVCoordinates().getPosition();
    Vector3D numPosition = numericIntermediateOrbit.getPVCoordinates().getPosition();
    Assert.assertEquals(0, kepPosition.subtract(numPosition).getNorm(), 10e-2);

}

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

@Test
public void testCartesian() throws OrekitException {

    // Propagation of the initial at t + dt
    final double dt = 3200;
    propagator.setOrbitType(OrbitType.CARTESIAN);
    final PVCoordinates finalState = propagator.propagate(initDate.shiftedBy(dt)).getPVCoordinates();
    final Vector3D pFin = finalState.getPosition();
    final Vector3D vFin = finalState.getVelocity();

    // Check results
    final PVCoordinates reference = initialState.shiftedBy(dt).getPVCoordinates();
    final Vector3D pRef = reference.getPosition();
    final Vector3D vRef = reference.getVelocity();
    Assert.assertEquals(0, pRef.subtract(pFin).getNorm(), 2e-4);
    Assert.assertEquals(0, vRef.subtract(vFin).getNorm(), 7e-8);

    try {//from www .  j a v a 2  s.  c  o  m
        propagator.getGeneratedEphemeris();
        Assert.fail("an exception should have been thrown");
    } catch (IllegalStateException ise) {
        // expected
    }
}

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

/** Build the rotation that transforms a pair of pv coordinates into another one.
        //from  w w  w. ja v  a  2s  .c o  m
 * <p><em>WARNING</em>! This method requires much more stringent assumptions on
 * its parameters than the similar {@link Rotation#Rotation(Vector3D, Vector3D,
 * Vector3D, Vector3D) constructor} from the {@link Rotation Rotation} class.
 * As far as the Rotation constructor is concerned, the {@code v} vector from
 * the second pair can be slightly misaligned. The Rotation constructor will
 * compensate for this misalignment and create a rotation that ensure {@code
 * v? = r(u?)} and {@code v  plane (r(u?), r(u))}. <em>THIS IS NOT
 * TRUE ANYMORE IN THIS CLASS</em>! As derivatives are involved and must be
 * preserved, this constructor works <em>only</em> if the two pairs are fully
 * consistent, i.e. if a rotation exists that fulfill all the requirements: {@code
 * v? = r(u?)}, {@code v = r(u)}, {@code dv?/dt = dr(u?)/dt}, {@code dv/dt
 * = dr(u)/dt}, {@code dv?/dt = dr(u?)/dt}, {@code dv/dt = dr(u)/dt}.</p>
 * @param u1 first vector of the origin pair
 * @param u2 second vector of the origin pair
 * @param v1 desired image of u1 by the rotation
 * @param v2 desired image of u2 by the rotation
 * @param tolerance relative tolerance factor used to check singularities
 * @exception OrekitException if the vectors are inconsistent for the
 * rotation to be found (null, aligned, ...)
 */
public AngularCoordinates(final PVCoordinates u1, final PVCoordinates u2, final PVCoordinates v1,
        final PVCoordinates v2, final double tolerance) throws OrekitException {

    try {
        // find the initial fixed rotation
        rotation = new Rotation(u1.getPosition(), u2.getPosition(), v1.getPosition(), v2.getPosition());

        // find rotation rate  such that
        //    v? = r(dot(u?)) - dot(v?)
        //    v = r(dot(u)) - dot(v)
        final Vector3D ru1Dot = rotation.applyTo(u1.getVelocity());
        final Vector3D ru2Dot = rotation.applyTo(u2.getVelocity());
        rotationRate = inverseCrossProducts(v1.getPosition(), ru1Dot.subtract(v1.getVelocity()),
                v2.getPosition(), ru2Dot.subtract(v2.getVelocity()), tolerance);

        // find rotation acceleration dot() such that
        // dot()  v? = r(dotdot(u?)) - 2   dot(v?) -    (  v?) - dotdot(v?)
        // dot()  v = r(dotdot(u)) - 2   dot(v) -    (  v) - dotdot(v)
        final Vector3D ru1DotDot = rotation.applyTo(u1.getAcceleration());
        final Vector3D oDotv1 = Vector3D.crossProduct(rotationRate, v1.getVelocity());
        final Vector3D oov1 = Vector3D.crossProduct(rotationRate,
                Vector3D.crossProduct(rotationRate, v1.getPosition()));
        final Vector3D c1 = new Vector3D(1, ru1DotDot, -2, oDotv1, -1, oov1, -1, v1.getAcceleration());
        final Vector3D ru2DotDot = rotation.applyTo(u2.getAcceleration());
        final Vector3D oDotv2 = Vector3D.crossProduct(rotationRate, v2.getVelocity());
        final Vector3D oov2 = Vector3D.crossProduct(rotationRate,
                Vector3D.crossProduct(rotationRate, v2.getPosition()));
        final Vector3D c2 = new Vector3D(1, ru2DotDot, -2, oDotv2, -1, oov2, -1, v2.getAcceleration());
        rotationAcceleration = inverseCrossProducts(v1.getPosition(), c1, v2.getPosition(), c2, tolerance);

    } catch (MathIllegalArgumentException miae) {
        throw new OrekitException(miae);
    } catch (MathArithmeticException mae) {
        throw new OrekitException(mae);
    }

}

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);/*  w  w w. j  av a  2 s  . c o  m*/
    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);
    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 testSpin() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    AngularCoordinates angularCoordinates = new AngularCoordinates(new Rotation(0.48, 0.64, 0.36, 0.48, false),
            new Vector3D(rate, Vector3D.PLUS_K));
    Assert.assertEquals(rate, angularCoordinates.getRotationRate().getNorm(), 1.0e-10);
    double dt = 10.0;
    AngularCoordinates shifted = angularCoordinates.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getRotationRate().getNorm(), 1.0e-10);
    Assert.assertEquals(rate * dt, Rotation.distance(angularCoordinates.getRotation(), shifted.getRotation()),
            1.0e-10);//from  ww  w.  j a  v a  2 s. co m

    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 = angularCoordinates.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Vector3D originalY = angularCoordinates.getRotation().applyInverseTo(Vector3D.PLUS_J);
    Vector3D originalZ = angularCoordinates.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(angularCoordinates.getRotation(), shifted.getRotation(),
            dt);
    Assert.assertEquals(0.0, forward.subtract(angularCoordinates.getRotationRate()).getNorm(), 1.0e-10);

    Vector3D reversed = AngularCoordinates.estimateRate(shifted.getRotation(), angularCoordinates.getRotation(),
            dt);
    Assert.assertEquals(0.0, reversed.add(angularCoordinates.getRotationRate()).getNorm(), 1.0e-10);

}

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

@Test
public void testShift() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    TimeStampedAngularCoordinates ac = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH,
            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;
    TimeStampedAngularCoordinates shifted = ac.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getRotationRate().getNorm(), 1.0e-10);
    Assert.assertEquals(alpha, Rotation.distance(ac.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 w w .java  2 s. 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.utils.TimeStampedAngularCoordinatesTest.java

@Test
public void testSpin() throws OrekitException {
    double rate = 2 * FastMath.PI / (12 * 60);
    TimeStampedAngularCoordinates ac = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH,
            new Rotation(0.48, 0.64, 0.36, 0.48, false), new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO);
    Assert.assertEquals(rate, ac.getRotationRate().getNorm(), 1.0e-10);
    double dt = 10.0;
    TimeStampedAngularCoordinates shifted = ac.shiftedBy(dt);
    Assert.assertEquals(rate, shifted.getRotationRate().getNorm(), 1.0e-10);
    Assert.assertEquals(rate * dt, Rotation.distance(ac.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 = ac.getRotation().applyInverseTo(Vector3D.PLUS_I);
    Vector3D originalY = ac.getRotation().applyInverseTo(Vector3D.PLUS_J);
    Vector3D originalZ = ac.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 = TimeStampedAngularCoordinates.estimateRate(ac.getRotation(), shifted.getRotation(), dt);
    Assert.assertEquals(0.0, forward.subtract(ac.getRotationRate()).getNorm(), 1.0e-10);

    Vector3D reversed = TimeStampedAngularCoordinates.estimateRate(shifted.getRotation(), ac.getRotation(), dt);
    Assert.assertEquals(0.0, reversed.add(ac.getRotationRate()).getNorm(), 1.0e-10);

}

From source file:org.rhwlab.dispim.nucleus.NamedNucleusFile.java

License:asdf

static public Vector3D divisionDirection(Nucleus nuc1, Nucleus nuc2) {
    double[] p0 = nuc1.getCenter();
    Vector3D v0 = new Vector3D(p0[0], p0[1], p0[2]);

    double[] p1 = nuc2.getCenter();
    Vector3D v1 = new Vector3D(p1[0], p1[1], p1[2]);

    return v1.subtract(v0);
}

From source file:se.toxbee.sleepfighter.challenge.shake.ShakeChallenge.java

/**
 * Handle an acceleration change event.//w  ww.  j  a v a  2  s  .c  o m
 * 
 * @param vector
 *            the current acceleration vector
 * @param time
 *            the time the acceleration vector was acquired, in nono
 *            seconds, since some time in the past defined by the system
 */
private void onAccelerationChange(Vector3D vector, long time) {
    // Only take vector difference into account, need a last vector
    if (lastVector != null) {
        // The difference of the vectors
        Vector3D diff = vector.subtract(lastVector);

        // Time difference in seconds
        double timeDiff = (double) (time - lastTime) / 1000000000;

        // The one dimensional "size" of the difference, there are probably
        // better things to measure
        double work = diff.getNorm();

        double workPerTime = work / timeDiff;

        // Only take effort above a set limit into account
        // Simple way to sort out small movements
        if (workPerTime > MIN_WORK) {
            // Increase the accumulator
            this.progress += work;

            updateProgress();

            checkIfCompleted();
        }
    }
    this.lastVector = vector;
    this.lastTime = time;
}