TimeStampedFieldAngularCoordinates.java

  1. /* Copyright 2002-2016 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.utils;

  18. import java.util.Collection;

  19. import org.apache.commons.math3.Field;
  20. import org.apache.commons.math3.RealFieldElement;
  21. import org.apache.commons.math3.analysis.interpolation.FieldHermiteInterpolator;
  22. import org.apache.commons.math3.geometry.euclidean.threed.FieldRotation;
  23. import org.apache.commons.math3.geometry.euclidean.threed.FieldVector3D;
  24. import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
  25. import org.apache.commons.math3.util.FastMath;
  26. import org.apache.commons.math3.util.MathArrays;
  27. import org.orekit.errors.OrekitException;
  28. import org.orekit.errors.OrekitInternalError;
  29. import org.orekit.errors.OrekitMessages;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.time.TimeStamped;

  32. /** {@link TimeStamped time-stamped} version of {@link FieldAngularCoordinates}.
  33.  * <p>Instances of this class are guaranteed to be immutable.</p>
  34.  * @param <T> the type of the field elements
  35.  * @author Luc Maisonobe
  36.  * @since 7.0
  37.  */
  38. public class TimeStampedFieldAngularCoordinates<T extends RealFieldElement<T>>
  39.     extends FieldAngularCoordinates<T> implements TimeStamped {

  40.     /** Serializable UID. */
  41.     private static final long serialVersionUID = 20140723L;

  42.     /** The date. */
  43.     private final AbsoluteDate date;

  44.     /** Builds a rotation/rotation rate pair.
  45.      * @param date coordinates date
  46.      * @param rotation rotation
  47.      * @param rotationRate FieldRotation<T> rate Ω (rad/s)
  48.      * @param rotationAcceleration FieldRotation<T> acceleration dΩ/dt (rad²/s²)
  49.      */
  50.     public TimeStampedFieldAngularCoordinates(final AbsoluteDate date,
  51.                                               final FieldRotation<T> rotation,
  52.                                               final FieldVector3D<T> rotationRate,
  53.                                               final FieldVector3D<T> rotationAcceleration) {
  54.         super(rotation, rotationRate, rotationAcceleration);
  55.         this.date = date;
  56.     }

  57.     /** {@inheritDoc} */
  58.     public AbsoluteDate getDate() {
  59.         return date;
  60.     }

  61.     /** Revert a rotation/rotation rate pair.
  62.      * Build a pair which reverse the effect of another pair.
  63.      * @return a new pair whose effect is the reverse of the effect
  64.      * of the instance
  65.      */
  66.     public TimeStampedFieldAngularCoordinates<T> revert() {
  67.         return new TimeStampedFieldAngularCoordinates<T>(date,
  68.                                                          getRotation().revert(),
  69.                                                          getRotation().applyInverseTo(getRotationRate().negate()),
  70.                                                          getRotation().applyInverseTo(getRotationAcceleration().negate()));
  71.     }

  72.     /** Get a time-shifted state.
  73.      * <p>
  74.      * The state can be slightly shifted to close dates. This shift is based on
  75.      * a simple linear model. It is <em>not</em> intended as a replacement for
  76.      * proper attitude propagation but should be sufficient for either small
  77.      * time shifts or coarse accuracy.
  78.      * </p>
  79.      * @param dt time shift in seconds
  80.      * @return a new state, shifted with respect to the instance (which is immutable)
  81.      */
  82.     public TimeStampedFieldAngularCoordinates<T> shiftedBy(final double dt) {
  83.         final FieldAngularCoordinates<T> sac = super.shiftedBy(dt);
  84.         return new TimeStampedFieldAngularCoordinates<T>(date.shiftedBy(dt),
  85.                                                          sac.getRotation(), sac.getRotationRate(), sac.getRotationAcceleration());

  86.     }

  87.     /** Add an offset from the instance.
  88.      * <p>
  89.      * We consider here that the offset FieldRotation<T> is applied first and the
  90.      * instance is applied afterward. Note that angular coordinates do <em>not</em>
  91.      * commute under this operation, i.e. {@code a.addOffset(b)} and {@code
  92.      * b.addOffset(a)} lead to <em>different</em> results in most cases.
  93.      * </p>
  94.      * <p>
  95.      * The two methods {@link #addOffset(FieldAngularCoordinates) addOffset} and
  96.      * {@link #subtractOffset(FieldAngularCoordinates) subtractOffset} are designed
  97.      * so that round trip applications are possible. This means that both {@code
  98.      * ac1.subtractOffset(ac2).addOffset(ac2)} and {@code
  99.      * ac1.addOffset(ac2).subtractOffset(ac2)} return angular coordinates equal to ac1.
  100.      * </p>
  101.      * @param offset offset to subtract
  102.      * @return new instance, with offset subtracted
  103.      * @see #subtractOffset(FieldAngularCoordinates)
  104.      */
  105.     public TimeStampedFieldAngularCoordinates<T> addOffset(final FieldAngularCoordinates<T> offset) {
  106.         final FieldVector3D<T> rOmega    = getRotation().applyTo(offset.getRotationRate());
  107.         final FieldVector3D<T> rOmegaDot = getRotation().applyTo(offset.getRotationAcceleration());
  108.         return new TimeStampedFieldAngularCoordinates<T>(date,
  109.                                                          getRotation().compose(offset.getRotation(), RotationConvention.VECTOR_OPERATOR),
  110.                                                          getRotationRate().add(rOmega),
  111.                                                          new FieldVector3D<T>( 1.0, getRotationAcceleration(),
  112.                                                                                1.0, rOmegaDot,
  113.                                                                               -1.0, FieldVector3D.crossProduct(getRotationRate(), rOmega)));
  114.     }

  115.     /** Subtract an offset from the instance.
  116.      * <p>
  117.      * We consider here that the offset Rotation is applied first and the
  118.      * instance is applied afterward. Note that angular coordinates do <em>not</em>
  119.      * commute under this operation, i.e. {@code a.subtractOffset(b)} and {@code
  120.      * b.subtractOffset(a)} lead to <em>different</em> results in most cases.
  121.      * </p>
  122.      * <p>
  123.      * The two methods {@link #addOffset(FieldAngularCoordinates) addOffset} and
  124.      * {@link #subtractOffset(FieldAngularCoordinates) subtractOffset} are designed
  125.      * so that round trip applications are possible. This means that both {@code
  126.      * ac1.subtractOffset(ac2).addOffset(ac2)} and {@code
  127.      * ac1.addOffset(ac2).subtractOffset(ac2)} return angular coordinates equal to ac1.
  128.      * </p>
  129.      * @param offset offset to subtract
  130.      * @return new instance, with offset subtracted
  131.      * @see #addOffset(FieldAngularCoordinates)
  132.      */
  133.     public TimeStampedFieldAngularCoordinates<T> subtractOffset(final FieldAngularCoordinates<T> offset) {
  134.         return addOffset(offset.revert());
  135.     }

  136.     /** Interpolate angular coordinates.
  137.      * <p>
  138.      * The interpolated instance is created by polynomial Hermite interpolation
  139.      * on Rodrigues vector ensuring FieldRotation<T> rate remains the exact derivative of FieldRotation<T>.
  140.      * </p>
  141.      * <p>
  142.      * This method is based on Sergei Tanygin's paper <a
  143.      * href="http://www.agi.com/downloads/resources/white-papers/Attitude-interpolation.pdf">Attitude
  144.      * Interpolation</a>, changing the norm of the vector to match the modified Rodrigues
  145.      * vector as described in Malcolm D. Shuster's paper <a
  146.      * href="http://www.ladispe.polito.it/corsi/Meccatronica/02JHCOR/2011-12/Slides/Shuster_Pub_1993h_J_Repsurv_scan.pdf">A
  147.      * Survey of Attitude Representations</a>. This change avoids the singularity at π.
  148.      * There is still a singularity at 2π, which is handled by slightly offsetting all FieldRotation<T>s
  149.      * when this singularity is detected.
  150.      * </p>
  151.      * <p>
  152.      * Note that even if first time derivatives (FieldRotation<T> rates)
  153.      * from sample can be ignored, the interpolated instance always includes
  154.      * interpolated derivatives. This feature can be used explicitly to
  155.      * compute these derivatives when it would be too complex to compute them
  156.      * from an analytical formula: just compute a few sample points from the
  157.      * explicit formula and set the derivatives to zero in these sample points,
  158.      * then use interpolation to add derivatives consistent with the FieldRotation<T>s.
  159.      * </p>
  160.      * @param date interpolation date
  161.      * @param filter filter for derivatives from the sample to use in interpolation
  162.      * @param sample sample points on which interpolation should be done
  163.      * @param <T> the type of the field elements
  164.      * @return a new position-velocity, interpolated at specified date
  165.      * @exception OrekitException if the number of point is too small for interpolating
  166.      */
  167.     @SuppressWarnings("unchecked")
  168.     public static <T extends RealFieldElement<T>>
  169.         TimeStampedFieldAngularCoordinates<T> interpolate(final AbsoluteDate date,
  170.                                                           final AngularDerivativesFilter filter,
  171.                                                           final Collection<TimeStampedFieldAngularCoordinates<T>> sample)
  172.         throws OrekitException {

  173.         // get field properties
  174.         final Field<T> field = sample.iterator().next().getRotation().getQ0().getField();
  175.         final T zero = field.getZero();
  176.         final T one  = field.getOne();

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

  180.         // set up a linear model canceling mean rotation rate
  181.         final FieldVector3D<T> meanRate;
  182.         if (filter != AngularDerivativesFilter.USE_R) {
  183.             FieldVector3D<T> sum = new FieldVector3D<T>(zero, zero, zero);
  184.             for (final TimeStampedFieldAngularCoordinates<T> datedAC : sample) {
  185.                 sum = sum.add(datedAC.getRotationRate());
  186.             }
  187.             meanRate = new FieldVector3D<T>(1.0 / sample.size(), sum);
  188.         } else {
  189.             if (sample.size() < 2) {
  190.                 throw new OrekitException(OrekitMessages.NOT_ENOUGH_DATA_FOR_INTERPOLATION,
  191.                                           sample.size());
  192.             }
  193.             FieldVector3D<T> sum = new FieldVector3D<T>(zero, zero, zero);
  194.             TimeStampedFieldAngularCoordinates<T> previous = null;
  195.             for (final TimeStampedFieldAngularCoordinates<T> datedAC : sample) {
  196.                 if (previous != null) {
  197.                     sum = sum.add(estimateRate(previous.getRotation(), datedAC.getRotation(),
  198.                                                datedAC.date.durationFrom(previous.getDate())));
  199.                 }
  200.                 previous = datedAC;
  201.             }
  202.             meanRate = new FieldVector3D<T>(1.0 / (sample.size() - 1), sum);
  203.         }
  204.         TimeStampedFieldAngularCoordinates<T> offset =
  205.                 new TimeStampedFieldAngularCoordinates<T>(date, new FieldRotation<T>(one, zero, zero, zero, false),
  206.                                                           meanRate, new FieldVector3D<T>(zero, zero, zero));

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

  209.             // offset adaptation parameters
  210.             restart = false;

  211.             // set up an interpolator taking derivatives into account
  212.             final FieldHermiteInterpolator<T> interpolator = new FieldHermiteInterpolator<T>();

  213.             // add sample points
  214.             final double[] previous = new double[] {
  215.                 1.0, 0.0, 0.0, 0.0
  216.             };

  217.             for (final TimeStampedFieldAngularCoordinates<T> ac : sample) {

  218.                 // remove linear offset from the current coordinates
  219.                 final T dt = zero.add(ac.date.durationFrom(date));
  220.                 final TimeStampedFieldAngularCoordinates<T> fixed = ac.subtractOffset(offset.shiftedBy(dt.getReal()));

  221.                 final T[][] rodrigues = getModifiedRodrigues(fixed, previous, threshold);
  222.                 if (rodrigues == null) {
  223.                     // the sample point is close to a modified Rodrigues vector singularity
  224.                     // we need to change the linear offset model to avoid this
  225.                     restart = true;
  226.                     break;
  227.                 }
  228.                 switch (filter) {
  229.                     case USE_RRA:
  230.                         // populate sample with rotation, rotation rate and acceleration data
  231.                         interpolator.addSamplePoint(dt, rodrigues[0], rodrigues[1], rodrigues[2]);
  232.                         break;
  233.                     case USE_RR:
  234.                         // populate sample with rotation and rotation rate data
  235.                         interpolator.addSamplePoint(dt, rodrigues[0], rodrigues[1]);
  236.                         break;
  237.                     case USE_R:
  238.                         // populate sample with rotation data only
  239.                         interpolator.addSamplePoint(dt, rodrigues[0]);
  240.                         break;
  241.                     default :
  242.                         // this should never happen
  243.                         throw new OrekitInternalError(null);
  244.                 }
  245.             }

  246.             if (restart) {
  247.                 // interpolation failed, some intermediate rotation was too close to 2π
  248.                 // we need to offset all rotations to avoid the singularity
  249.                 offset = offset.addOffset(new FieldAngularCoordinates<T>(new FieldRotation<T>(new FieldVector3D<T>(one, zero, zero),
  250.                                                                                               zero.add(epsilon),
  251.                                                                                               RotationConvention.VECTOR_OPERATOR),
  252.                                                                          new FieldVector3D<T>(zero, zero, zero),
  253.                                                                          new FieldVector3D<T>(zero, zero, zero)));
  254.             } else {
  255.                 // interpolation succeeded with the current offset
  256.                 final T[][] p = interpolator.derivatives(field.getZero(), 2);
  257.                 return createFromModifiedRodrigues(p, offset);
  258.             }

  259.         }

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

  262.     }

  263.     /** Create a 6 elements array.
  264.      * @param field field to which coordinates belong
  265.      * @param a0 first element
  266.      * @param a1 second element
  267.      * @param a2 third element
  268.      * @param a3 fourth element
  269.      * @param a4 fifth element
  270.      * @param a5 sixth element
  271.      * @param <T> the type of the field elements
  272.      * @return array containing a0, a1, a2, a3, a4, a5
  273.      */
  274.     private static <T extends RealFieldElement<T>> T[] array6(final Field<T> field,
  275.                                                               final T a0, final T a1, final T a2,
  276.                                                               final T a3, final T a4, final T a5) {
  277.         final T[] array = MathArrays.buildArray(field, 6);
  278.         array[0] = a0;
  279.         array[1] = a1;
  280.         array[2] = a2;
  281.         array[3] = a3;
  282.         array[4] = a4;
  283.         array[5] = a5;
  284.         return array;
  285.     }

  286.     /** Create a 3x3 matrix.
  287.      * @param field field to which coordinates belong
  288.      * @param a00 first element, first row
  289.      * @param a01 second element, first row
  290.      * @param a02 third element, first row
  291.      * @param a10 first element, second row
  292.      * @param a11 second element, second row
  293.      * @param a12 third element, second row
  294.      * @param a20 first element, third row
  295.      * @param a21 second element, third row
  296.      * @param a22 third element, third row
  297.      * @param <T> the type of the field elements
  298.      * @return array containing a0, a1, a2
  299.      */
  300.     private static <T extends RealFieldElement<T>> T[][] matrix33(final Field<T> field,
  301.                                                                   final T a00, final T a01, final T a02,
  302.                                                                   final T a10, final T a11, final T a12,
  303.                                                                   final T a20, final T a21, final T a22) {
  304.         final T[][] matrix = MathArrays.buildArray(field, 3, 3);
  305.         matrix[0][0] = a00;
  306.         matrix[0][1] = a01;
  307.         matrix[0][2] = a02;
  308.         matrix[1][0] = a10;
  309.         matrix[1][1] = a11;
  310.         matrix[1][2] = a12;
  311.         matrix[2][0] = a20;
  312.         matrix[2][1] = a21;
  313.         matrix[2][2] = a22;
  314.         return matrix;
  315.     }

  316.     /** Convert rotation, rate and acceleration to modified Rodrigues vector and derivatives.
  317.      * <p>
  318.      * The modified Rodrigues vector is tan(θ/4) u where θ and u are the
  319.      * rotation angle and axis respectively.
  320.      * </p>
  321.      * @param fixed coordinates to convert, with offset already fixed
  322.      * @param previous previous quaternion used
  323.      * @param threshold threshold for rotations too close to 2π
  324.      * @param <T> the type of the field elements
  325.      * @return modified Rodrigues vector and derivative, or null if rotation is too close to 2π
  326.      */
  327.     private static <T extends RealFieldElement<T>> T[][] getModifiedRodrigues(final TimeStampedFieldAngularCoordinates<T> fixed,
  328.                                                                               final double[] previous, final double threshold) {

  329.         // make sure all interpolated points will be on the same branch
  330.         T q0 = fixed.getRotation().getQ0();
  331.         T q1 = fixed.getRotation().getQ1();
  332.         T q2 = fixed.getRotation().getQ2();
  333.         T q3 = fixed.getRotation().getQ3();
  334.         if (MathArrays.linearCombination(q0.getReal(), previous[0],
  335.                                          q1.getReal(), previous[1],
  336.                                          q2.getReal(), previous[2],
  337.                                          q3.getReal(), previous[3]) < 0) {
  338.             q0 = q0.negate();
  339.             q1 = q1.negate();
  340.             q2 = q2.negate();
  341.             q3 = q3.negate();
  342.         }
  343.         previous[0] = q0.getReal();
  344.         previous[1] = q1.getReal();
  345.         previous[2] = q2.getReal();
  346.         previous[3] = q3.getReal();

  347.         // check modified Rodrigues vector singularity
  348.         if (q0.getReal() < threshold) {
  349.             // this is an intermediate point that happens to be 2PI away from reference
  350.             // we need to change the linear offset model to avoid this point
  351.             return null;
  352.         }

  353.         final Field<T> field = q0.getField();

  354.         final T oX    = fixed.getRotationRate().getX();
  355.         final T oY    = fixed.getRotationRate().getY();
  356.         final T oZ    = fixed.getRotationRate().getZ();
  357.         final T oXDot = fixed.getRotationAcceleration().getX();
  358.         final T oYDot = fixed.getRotationAcceleration().getY();
  359.         final T oZDot = fixed.getRotationAcceleration().getZ();

  360.         // first time-derivatives of the quaternion
  361.         final T q0Dot = q0.linearCombination(q1.negate(), oX, q2.negate(), oY, q3.negate(), oZ).multiply(0.5);
  362.         final T q1Dot = q1.linearCombination(q0,          oX, q3.negate(), oY, q2,          oZ).multiply(0.5);
  363.         final T q2Dot = q2.linearCombination(q3,          oX, q0,          oY, q1.negate(), oZ).multiply(0.5);
  364.         final T q3Dot = q3.linearCombination(q2.negate(), oX, q1,          oY, q0,          oZ).multiply(0.5);

  365.         // second time-derivatives of the quaternion
  366.         final T q0DotDot = q0.linearCombination(array6(field, q1, q2,  q3, q1Dot, q2Dot,  q3Dot),
  367.                                                 array6(field, oXDot, oYDot, oZDot, oX, oY, oZ)).multiply(-0.5);
  368.         final T q1DotDot = q1.linearCombination(array6(field, q0, q2, q3.negate(), q0Dot, q2Dot, q3Dot.negate()),
  369.                                                 array6(field, oXDot, oZDot, oYDot, oX, oZ, oY)).multiply(0.5);
  370.         final T q2DotDot = q2.linearCombination(array6(field, q0, q3, q1.negate(), q0Dot, q3Dot, q1Dot.negate()),
  371.                                                 array6(field, oYDot, oXDot, oZDot, oY, oX, oZ)).multiply(0.5);
  372.         final T q3DotDot = q3.linearCombination(array6(field, q0, q1, q2.negate(), q0Dot, q1Dot, q2Dot.negate()),
  373.                                                 array6(field, oZDot, oYDot, oXDot, oZ, oY, oX)).multiply(0.5);

  374.         // the modified Rodrigues is tan(θ/4) u where θ and u are the rotation angle and axis respectively
  375.         // this can be rewritten using quaternion components:
  376.         //      r (q₁ / (1+q₀), q₂ / (1+q₀), q₃ / (1+q₀))
  377.         // applying the derivation chain rule to previous expression gives rDot and rDotDot
  378.         final T inv          = q0.add(1.0).reciprocal();
  379.         final T mTwoInvQ0Dot = inv.multiply(q0Dot).multiply(-2);

  380.         final T r1       = inv.multiply(q1);
  381.         final T r2       = inv.multiply(q2);
  382.         final T r3       = inv.multiply(q3);

  383.         final T mInvR1   = inv.multiply(r1).negate();
  384.         final T mInvR2   = inv.multiply(r2).negate();
  385.         final T mInvR3   = inv.multiply(r3).negate();

  386.         final T r1Dot    = r1.linearCombination(inv, q1Dot, mInvR1, q0Dot);
  387.         final T r2Dot    = r2.linearCombination(inv, q2Dot, mInvR2, q0Dot);
  388.         final T r3Dot    = r3.linearCombination(inv, q3Dot, mInvR3, q0Dot);

  389.         final T r1DotDot = r1.linearCombination(inv, q1DotDot, mTwoInvQ0Dot, r1Dot, mInvR1, q0DotDot);
  390.         final T r2DotDot = r2.linearCombination(inv, q2DotDot, mTwoInvQ0Dot, r2Dot, mInvR2, q0DotDot);
  391.         final T r3DotDot = r3.linearCombination(inv, q3DotDot, mTwoInvQ0Dot, r3Dot, mInvR3, q0DotDot);

  392.         return matrix33(field,
  393.                         r1,       r2,       r3,
  394.                         r1Dot,    r2Dot,    r3Dot,
  395.                         r1DotDot, r2DotDot, r3DotDot);

  396.     }

  397.     /** Convert a modified Rodrigues vector and derivatives to angular coordinates.
  398.      * @param r modified Rodrigues vector (with first derivatives)
  399.      * @param offset linear offset model to add (its date must be consistent with the modified Rodrigues vector)
  400.      * @param <T> the type of the field elements
  401.      * @return angular coordinates
  402.      */
  403.     private static <T extends RealFieldElement<T>>
  404.         TimeStampedFieldAngularCoordinates<T> createFromModifiedRodrigues(final T[][] r,
  405.                                                                           final TimeStampedFieldAngularCoordinates<T> offset) {

  406.         // rotation
  407.         final T rSquared = r[0][0].multiply(r[0][0]).add(r[0][1].multiply(r[0][1])).add(r[0][2].multiply(r[0][2]));
  408.         final T oPQ0     = rSquared.add(1).reciprocal().multiply(2);
  409.         final T q0       = oPQ0.subtract(1);
  410.         final T q1       = oPQ0.multiply(r[0][0]);
  411.         final T q2       = oPQ0.multiply(r[0][1]);
  412.         final T q3       = oPQ0.multiply(r[0][2]);

  413.         // rotation rate
  414.         final T oPQ02    = oPQ0.multiply(oPQ0);
  415.         final T q0Dot    = oPQ02.negate().multiply(q0.linearCombination(r[0][0], r[1][0], r[0][1], r[1][1],  r[0][2], r[1][2]));
  416.         final T q1Dot    = oPQ0.multiply(r[1][0]).add(r[0][0].multiply(q0Dot));
  417.         final T q2Dot    = oPQ0.multiply(r[1][1]).add(r[0][1].multiply(q0Dot));
  418.         final T q3Dot    = oPQ0.multiply(r[1][2]).add(r[0][2].multiply(q0Dot));
  419.         final T oX       = q1.linearCombination(q1.negate(), q0Dot, q0,          q1Dot, q3,          q2Dot, q2.negate(), q3Dot).multiply(2);
  420.         final T oY       = q2.linearCombination(q2.negate(), q0Dot, q3.negate(), q1Dot, q0,          q2Dot, q1,          q3Dot).multiply(2);
  421.         final T oZ       = q3.linearCombination(q3.negate(), q0Dot, q2,          q1Dot, q1.negate(), q2Dot, q0,          q3Dot).multiply(2);

  422.         // rotation acceleration
  423.         final T q0DotDot = q0.getField().getOne().subtract(q0).divide(oPQ0).multiply(q0Dot).multiply(q0Dot).
  424.                            subtract(oPQ02.multiply(q0.linearCombination(r[0][0], r[2][0], r[0][1], r[2][1], r[0][2], r[2][2]))).
  425.                            subtract(q1Dot.multiply(q1Dot).add(q2Dot.multiply(q2Dot)).add(q3Dot.multiply(q3Dot)));
  426.         final T q1DotDot = q1.linearCombination(oPQ0, r[2][0], r[1][0].multiply(2), q0Dot, r[0][0], q0DotDot);
  427.         final T q2DotDot = q2.linearCombination(oPQ0, r[2][1], r[1][1].multiply(2), q0Dot, r[0][1], q0DotDot);
  428.         final T q3DotDot = q3.linearCombination(oPQ0, r[2][2], r[1][2].multiply(2), q0Dot, r[0][2], q0DotDot);
  429.         final T oXDot    = q1.linearCombination(q1.negate(), q0DotDot, q0,          q1DotDot, q3,          q2DotDot, q2.negate(), q3DotDot).multiply(2);
  430.         final T oYDot    = q2.linearCombination(q2.negate(), q0DotDot, q3.negate(), q1DotDot, q0,          q2DotDot, q1,          q3DotDot).multiply(2);
  431.         final T oZDot    = q3.linearCombination(q3.negate(), q0DotDot, q2,          q1DotDot, q1.negate(), q2DotDot, q0,          q3DotDot).multiply(2);

  432.         return new TimeStampedFieldAngularCoordinates<T>(offset.getDate(),
  433.                                                          new FieldRotation<T>(q0, q1, q2, q3, false),
  434.                                                          new FieldVector3D<T>(oX, oY, oZ),
  435.                                                          new FieldVector3D<T>(oXDot, oYDot, oZDot)).addOffset(offset);

  436.     }

  437. }