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

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

Introduction

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

Prototype

public Vector3D add(final Vector<Euclidean3D> v) 

Source Link

Usage

From source file:org.orekit.models.earth.GeoidTest.java

/**
 * check {@link Geoid#getIntersectionPoint(Line, Vector3D, Frame,
 * AbsoluteDate)} handles frame transformations correctly
 *
 * @throws OrekitException on error//from ww w  .java 2s  .c  o m
 */
@Test
public void testGetIntersectionPointFrame() throws OrekitException {
    // setup
    Geoid geoid = getComponent();
    Frame frame = new Frame(geoid.getBodyFrame(),
            new Transform(date, new Transform(date, new Vector3D(-1, 2, -3), new Vector3D(4, -5, 6)),
                    new Transform(date, new Rotation(-7, 8, -9, 10, true), new Vector3D(-11, 12, -13))),
            "test frame");
    GeodeticPoint gp = new GeodeticPoint(FastMath.toRadians(46.8743190), FastMath.toRadians(102.4487290), 0);
    Vector3D expected = geoid.transform(gp);
    // glancing line: 10% vertical and 90% north (~6 deg elevation)
    Vector3D slope = gp.getZenith().scalarMultiply(0.1).add(gp.getNorth().scalarMultiply(0.9));
    Vector3D close = expected.add(slope.scalarMultiply(100));
    Line line = new Line(expected.add(slope), close, 0);
    Transform xform = geoid.getBodyFrame().getTransformTo(frame, date);
    // transform to test frame
    close = xform.transformPosition(close);
    line = xform.transformLine(line);

    // action
    GeodeticPoint actual = geoid.getIntersectionPoint(line, close, frame, date);

    // verify, 1 um position accuracy at Earth's surface
    assertThat(actual, geodeticPointCloseTo(gp, 1e-6));
}

From source file:org.orekit.models.earth.GeoidTest.java

/**
 * check {@link Geoid#getIntersectionPoint(Line, Vector3D, Frame,
 * AbsoluteDate)} returns null when there is no intersection
 *
 * @throws OrekitException on error/*from ww  w  .  j  a  v  a2 s  .  c o  m*/
 */
@Test
public void testGetIntersectionPointNoIntersection() throws OrekitException {
    Geoid geoid = getComponent();
    Vector3D closeMiss = new Vector3D(geoid.getEllipsoid().getEquatorialRadius() + 18, 0, 0);
    Line line = new Line(closeMiss, closeMiss.add(Vector3D.PLUS_J), 0);

    // action
    final GeodeticPoint actual = geoid.getIntersectionPoint(line, closeMiss, geoid.getBodyFrame(), date);

    // verify
    assertThat(actual, nullValue());
}

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 www.  jav a  2 s  .com

    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.TimeStampedAngularCoordinates.java

/** Interpolate angular coordinates.
 * <p>//from   w ww.j a  va 2  s .  c  om
 * The interpolated instance is created by polynomial Hermite interpolation
 * on Rodrigues vector ensuring rotation rate remains the exact derivative of rotation.
 * </p>
 * <p>
 * This method is based on Sergei Tanygin's paper <a
 * href="http://www.agi.com/downloads/resources/white-papers/Attitude-interpolation.pdf">Attitude
 * Interpolation</a>, changing the norm of the vector to match the modified Rodrigues
 * vector as described in Malcolm D. Shuster's paper <a
 * href="http://www.ladispe.polito.it/corsi/Meccatronica/02JHCOR/2011-12/Slides/Shuster_Pub_1993h_J_Repsurv_scan.pdf">A
 * Survey of Attitude Representations</a>. This change avoids the singularity at .
 * There is still a singularity at 2, which is handled by slightly offsetting all rotations
 * when this singularity is detected.
 * </p>
 * <p>
 * Note that even if first and second time derivatives (rotation rates and acceleration)
 * from sample can be ignored, the interpolated instance always includes
 * interpolated derivatives. This feature can be used explicitly to
 * compute these derivatives when it would be too complex to compute them
 * from an analytical formula: just compute a few sample points from the
 * explicit formula and set the derivatives to zero in these sample points,
 * then use interpolation to add derivatives consistent with the rotations.
 * </p>
 * @param date interpolation date
 * @param filter filter for derivatives from the sample to use in interpolation
 * @param sample sample points on which interpolation should be done
 * @return a new position-velocity, interpolated at specified date
 * @exception OrekitException if the number of point is too small for interpolating
 */
public static TimeStampedAngularCoordinates interpolate(final AbsoluteDate date,
        final AngularDerivativesFilter filter, final Collection<TimeStampedAngularCoordinates> sample)
        throws OrekitException {

    // set up safety elements for 2 singularity avoidance
    final double epsilon = 2 * FastMath.PI / sample.size();
    final double threshold = FastMath.min(-(1.0 - 1.0e-4), -FastMath.cos(epsilon / 4));

    // set up a linear model canceling mean rotation rate
    final Vector3D meanRate;
    if (filter != AngularDerivativesFilter.USE_R) {
        Vector3D sum = Vector3D.ZERO;
        for (final TimeStampedAngularCoordinates datedAC : sample) {
            sum = sum.add(datedAC.getRotationRate());
        }
        meanRate = new Vector3D(1.0 / sample.size(), sum);
    } else {
        if (sample.size() < 2) {
            throw new OrekitException(OrekitMessages.NOT_ENOUGH_DATA_FOR_INTERPOLATION, sample.size());
        }
        Vector3D sum = Vector3D.ZERO;
        TimeStampedAngularCoordinates previous = null;
        for (final TimeStampedAngularCoordinates datedAC : sample) {
            if (previous != null) {
                sum = sum.add(estimateRate(previous.getRotation(), datedAC.getRotation(),
                        datedAC.date.durationFrom(previous.date)));
            }
            previous = datedAC;
        }
        meanRate = new Vector3D(1.0 / (sample.size() - 1), sum);
    }
    TimeStampedAngularCoordinates offset = new TimeStampedAngularCoordinates(date, Rotation.IDENTITY, meanRate,
            Vector3D.ZERO);

    boolean restart = true;
    for (int i = 0; restart && i < sample.size() + 2; ++i) {

        // offset adaptation parameters
        restart = false;

        // set up an interpolator taking derivatives into account
        final HermiteInterpolator interpolator = new HermiteInterpolator();

        // add sample points
        double sign = +1.0;
        Rotation previous = Rotation.IDENTITY;

        for (final TimeStampedAngularCoordinates ac : sample) {

            // remove linear offset from the current coordinates
            final double dt = ac.date.durationFrom(date);
            final TimeStampedAngularCoordinates fixed = ac.subtractOffset(offset.shiftedBy(dt));

            // make sure all interpolated points will be on the same branch
            final double dot = MathArrays.linearCombination(fixed.getRotation().getQ0(), previous.getQ0(),
                    fixed.getRotation().getQ1(), previous.getQ1(), fixed.getRotation().getQ2(),
                    previous.getQ2(), fixed.getRotation().getQ3(), previous.getQ3());
            sign = FastMath.copySign(1.0, dot * sign);
            previous = fixed.getRotation();

            // check modified Rodrigues vector singularity
            if (fixed.getRotation().getQ0() * sign < threshold) {
                // the sample point is close to a modified Rodrigues vector singularity
                // we need to change the linear offset model to avoid this
                restart = true;
                break;
            }

            final double[][] rodrigues = fixed.getModifiedRodrigues(sign);
            switch (filter) {
            case USE_RRA:
                // populate sample with rotation, rotation rate and acceleration data
                interpolator.addSamplePoint(dt, rodrigues[0], rodrigues[1], rodrigues[2]);
                break;
            case USE_RR:
                // populate sample with rotation and rotation rate data
                interpolator.addSamplePoint(dt, rodrigues[0], rodrigues[1]);
                break;
            case USE_R:
                // populate sample with rotation data only
                interpolator.addSamplePoint(dt, rodrigues[0]);
                break;
            default:
                // this should never happen
                throw new OrekitInternalError(null);
            }
        }

        if (restart) {
            // interpolation failed, some intermediate rotation was too close to 2
            // we need to offset all rotations to avoid the singularity
            offset = offset.addOffset(new AngularCoordinates(new Rotation(Vector3D.PLUS_I, epsilon),
                    Vector3D.ZERO, Vector3D.ZERO));
        } else {
            // interpolation succeeded with the current offset
            final DerivativeStructure zero = new DerivativeStructure(1, 2, 0, 0.0);
            final DerivativeStructure[] p = interpolator.value(zero);
            final AngularCoordinates ac = createFromModifiedRodrigues(
                    new double[][] { { p[0].getValue(), p[1].getValue(), p[2].getValue() },
                            { p[0].getPartialDerivative(1), p[1].getPartialDerivative(1),
                                    p[2].getPartialDerivative(1) },
                            { p[0].getPartialDerivative(2), p[1].getPartialDerivative(2),
                                    p[2].getPartialDerivative(2) } });
            return new TimeStampedAngularCoordinates(offset.getDate(), ac.getRotation(), ac.getRotationRate(),
                    ac.getRotationAcceleration()).addOffset(offset);
        }

    }

    // this should never happen
    throw new OrekitInternalError(null);

}

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);

}