FieldAngularCoordinates.java

  1. /* Copyright 2002-2020 CS Group
  2.  * Licensed to CS Group (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 org.hipparchus.Field;
  19. import org.hipparchus.RealFieldElement;
  20. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  21. import org.hipparchus.analysis.differentiation.FDSFactory;
  22. import org.hipparchus.analysis.differentiation.FieldDerivativeStructure;
  23. import org.hipparchus.exception.LocalizedCoreFormats;
  24. import org.hipparchus.exception.MathIllegalArgumentException;
  25. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  26. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  27. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  28. import org.hipparchus.linear.FieldDecompositionSolver;
  29. import org.hipparchus.linear.FieldMatrix;
  30. import org.hipparchus.linear.FieldQRDecomposition;
  31. import org.hipparchus.linear.FieldVector;
  32. import org.hipparchus.linear.MatrixUtils;
  33. import org.hipparchus.util.MathArrays;
  34. import org.orekit.errors.OrekitException;
  35. import org.orekit.errors.OrekitMessages;

  36. /** Simple container for rotation / rotation rate pairs, using {@link
  37.  * RealFieldElement}.
  38.  * <p>
  39.  * The state can be slightly shifted to close dates. This shift is based on
  40.  * a simple quadratic model. It is <em>not</em> intended as a replacement for
  41.  * proper attitude propagation but should be sufficient for either small
  42.  * time shifts or coarse accuracy.
  43.  * </p>
  44.  * <p>
  45.  * This class is the angular counterpart to {@link FieldPVCoordinates}.
  46.  * </p>
  47.  * <p>Instances of this class are guaranteed to be immutable.</p>
  48.  * @param <T> the type of the field elements
  49.  * @author Luc Maisonobe
  50.  * @since 6.0
  51.  * @see AngularCoordinates
  52.  */
  53. public class FieldAngularCoordinates<T extends RealFieldElement<T>> {


  54.     /** rotation. */
  55.     private final FieldRotation<T> rotation;

  56.     /** rotation rate. */
  57.     private final FieldVector3D<T> rotationRate;

  58.     /** rotation acceleration. */
  59.     private final FieldVector3D<T> rotationAcceleration;

  60.     /** Builds a rotation/rotation rate pair.
  61.      * @param rotation rotation
  62.      * @param rotationRate rotation rate Ω (rad/s)
  63.      */
  64.     public FieldAngularCoordinates(final FieldRotation<T> rotation,
  65.                                    final FieldVector3D<T> rotationRate) {
  66.         this(rotation, rotationRate,
  67.              new FieldVector3D<>(rotation.getQ0().getField().getZero(),
  68.                                  rotation.getQ0().getField().getZero(),
  69.                                  rotation.getQ0().getField().getZero()));
  70.     }

  71.     /** Builds a rotation / rotation rate / rotation acceleration triplet.
  72.      * @param rotation i.e. the orientation of the vehicle
  73.      * @param rotationRate rotation rate rate Ω, i.e. the spin vector (rad/s)
  74.      * @param rotationAcceleration angular acceleration vector dΩ/dt (rad²/s²)
  75.      */
  76.     public FieldAngularCoordinates(final FieldRotation<T> rotation,
  77.                                    final FieldVector3D<T> rotationRate,
  78.                                    final FieldVector3D<T> rotationAcceleration) {
  79.         this.rotation             = rotation;
  80.         this.rotationRate         = rotationRate;
  81.         this.rotationAcceleration = rotationAcceleration;
  82.     }

  83.     /** Build the rotation that transforms a pair of pv coordinates into another one.

  84.      * <p><em>WARNING</em>! This method requires much more stringent assumptions on
  85.      * its parameters than the similar {@link FieldRotation#FieldRotation(FieldVector3D, FieldVector3D,
  86.      * FieldVector3D, FieldVector3D) constructor} from the {@link FieldRotation FieldRotation} class.
  87.      * As far as the FieldRotation constructor is concerned, the {@code v₂} vector from
  88.      * the second pair can be slightly misaligned. The FieldRotation constructor will
  89.      * compensate for this misalignment and create a rotation that ensure {@code
  90.      * v₁ = r(u₁)} and {@code v₂ ∈ plane (r(u₁), r(u₂))}. <em>THIS IS NOT
  91.      * TRUE ANYMORE IN THIS CLASS</em>! As derivatives are involved and must be
  92.      * preserved, this constructor works <em>only</em> if the two pairs are fully
  93.      * consistent, i.e. if a rotation exists that fulfill all the requirements: {@code
  94.      * v₁ = r(u₁)}, {@code v₂ = r(u₂)}, {@code dv₁/dt = dr(u₁)/dt}, {@code dv₂/dt
  95.      * = dr(u₂)/dt}, {@code d²v₁/dt² = d²r(u₁)/dt²}, {@code d²v₂/dt² = d²r(u₂)/dt²}.</p>
  96.      * @param u1 first vector of the origin pair
  97.      * @param u2 second vector of the origin pair
  98.      * @param v1 desired image of u1 by the rotation
  99.      * @param v2 desired image of u2 by the rotation
  100.      * @param tolerance relative tolerance factor used to check singularities
  101.      */
  102.     public FieldAngularCoordinates(final FieldPVCoordinates<T> u1, final FieldPVCoordinates<T> u2,
  103.                                    final FieldPVCoordinates<T> v1, final FieldPVCoordinates<T> v2,
  104.                                    final double tolerance) {

  105.         try {
  106.             // find the initial fixed rotation
  107.             rotation = new FieldRotation<>(u1.getPosition(), u2.getPosition(),
  108.                                            v1.getPosition(), v2.getPosition());

  109.             // find rotation rate Ω such that
  110.             //  Ω ⨯ v₁ = r(dot(u₁)) - dot(v₁)
  111.             //  Ω ⨯ v₂ = r(dot(u₂)) - dot(v₂)
  112.             final FieldVector3D<T> ru1Dot = rotation.applyTo(u1.getVelocity());
  113.             final FieldVector3D<T> ru2Dot = rotation.applyTo(u2.getVelocity());


  114.             rotationRate = inverseCrossProducts(v1.getPosition(), ru1Dot.subtract(v1.getVelocity()),
  115.                                                 v2.getPosition(), ru2Dot.subtract(v2.getVelocity()),
  116.                                                 tolerance);


  117.             // find rotation acceleration dot(Ω) such that
  118.             // dot(Ω) ⨯ v₁ = r(dotdot(u₁)) - 2 Ω ⨯ dot(v₁) - Ω ⨯  (Ω ⨯ v₁) - dotdot(v₁)
  119.             // dot(Ω) ⨯ v₂ = r(dotdot(u₂)) - 2 Ω ⨯ dot(v₂) - Ω ⨯  (Ω ⨯ v₂) - dotdot(v₂)
  120.             final FieldVector3D<T> ru1DotDot = rotation.applyTo(u1.getAcceleration());
  121.             final FieldVector3D<T> oDotv1    = FieldVector3D.crossProduct(rotationRate, v1.getVelocity());
  122.             final FieldVector3D<T> oov1      = FieldVector3D.crossProduct(rotationRate, rotationRate.crossProduct(v1.getPosition()));
  123.             final FieldVector3D<T> c1        = new FieldVector3D<>(1, ru1DotDot, -2, oDotv1, -1, oov1, -1, v1.getAcceleration());
  124.             final FieldVector3D<T> ru2DotDot = rotation.applyTo(u2.getAcceleration());
  125.             final FieldVector3D<T> oDotv2    = FieldVector3D.crossProduct(rotationRate, v2.getVelocity());
  126.             final FieldVector3D<T> oov2      = FieldVector3D.crossProduct(rotationRate, rotationRate.crossProduct( v2.getPosition()));
  127.             final FieldVector3D<T> c2        = new FieldVector3D<>(1, ru2DotDot, -2, oDotv2, -1, oov2, -1, v2.getAcceleration());
  128.             rotationAcceleration     = inverseCrossProducts(v1.getPosition(), c1, v2.getPosition(), c2, tolerance);

  129.         } catch (MathIllegalArgumentException miae) {
  130.             throw new OrekitException(miae);
  131.         }

  132.     }

  133.     /** Builds a FieldAngularCoordinates from a field and a regular AngularCoordinates.
  134.      * @param field field for the components
  135.      * @param ang AngularCoordinates to convert
  136.      */
  137.     public FieldAngularCoordinates(final Field<T> field, final AngularCoordinates ang) {
  138.         this.rotation             = new FieldRotation<>(field, ang.getRotation());
  139.         this.rotationRate         = new FieldVector3D<>(field, ang.getRotationRate());
  140.         this.rotationAcceleration = new FieldVector3D<>(field, ang.getRotationAcceleration());
  141.     }

  142.     /** Builds a FieldAngularCoordinates from  a {@link FieldRotation}&lt;{@link FieldDerivativeStructure}&gt;.
  143.      * <p>
  144.      * The rotation components must have time as their only derivation parameter and
  145.      * have consistent derivation orders.
  146.      * </p>
  147.      * @param r rotation with time-derivatives embedded within the coordinates
  148.      * @since 9.2
  149.      */
  150.     public FieldAngularCoordinates(final FieldRotation<FieldDerivativeStructure<T>> r) {

  151.         final T q0       = r.getQ0().getValue();
  152.         final T q1       = r.getQ1().getValue();
  153.         final T q2       = r.getQ2().getValue();
  154.         final T q3       = r.getQ3().getValue();

  155.         rotation     = new FieldRotation<>(q0, q1, q2, q3, false);
  156.         if (r.getQ0().getOrder() >= 1) {
  157.             final T q0Dot    = r.getQ0().getPartialDerivative(1);
  158.             final T q1Dot    = r.getQ1().getPartialDerivative(1);
  159.             final T q2Dot    = r.getQ2().getPartialDerivative(1);
  160.             final T q3Dot    = r.getQ3().getPartialDerivative(1);
  161.             rotationRate =
  162.                     new FieldVector3D<>(q0.linearCombination(q1.negate(), q0Dot, q0,          q1Dot,
  163.                                                              q3,          q2Dot, q2.negate(), q3Dot).multiply(2),
  164.                                         q0.linearCombination(q2.negate(), q0Dot, q3.negate(), q1Dot,
  165.                                                              q0,          q2Dot, q1,          q3Dot).multiply(2),
  166.                                         q0.linearCombination(q3.negate(), q0Dot, q2,          q1Dot,
  167.                                                              q1.negate(), q2Dot, q0,          q3Dot).multiply(2));
  168.             if (r.getQ0().getOrder() >= 2) {
  169.                 final T q0DotDot = r.getQ0().getPartialDerivative(2);
  170.                 final T q1DotDot = r.getQ1().getPartialDerivative(2);
  171.                 final T q2DotDot = r.getQ2().getPartialDerivative(2);
  172.                 final T q3DotDot = r.getQ3().getPartialDerivative(2);
  173.                 rotationAcceleration =
  174.                         new FieldVector3D<>(q0.linearCombination(q1.negate(), q0DotDot, q0,          q1DotDot,
  175.                                                                  q3,          q2DotDot, q2.negate(), q3DotDot).multiply(2),
  176.                                             q0.linearCombination(q2.negate(), q0DotDot, q3.negate(), q1DotDot,
  177.                                                                  q0,          q2DotDot, q1,          q3DotDot).multiply(2),
  178.                                             q0.linearCombination(q3.negate(), q0DotDot, q2,          q1DotDot,
  179.                                                                  q1.negate(), q2DotDot, q0,          q3DotDot).multiply(2));
  180.             } else {
  181.                 rotationAcceleration = FieldVector3D.getZero(q0.getField());
  182.             }
  183.         } else {
  184.             rotationRate         = FieldVector3D.getZero(q0.getField());
  185.             rotationAcceleration = FieldVector3D.getZero(q0.getField());
  186.         }

  187.     }

  188.     /** Fixed orientation parallel with reference frame
  189.      * (identity rotation, zero rotation rate and acceleration).
  190.      * @param field field for the components
  191.      * @param <T> the type of the field elements
  192.      * @return a new fixed orientation parallel with reference frame
  193.      */
  194.     public static <T extends RealFieldElement<T>> FieldAngularCoordinates<T> getIdentity(final Field<T> field) {
  195.         return new FieldAngularCoordinates<>(field, AngularCoordinates.IDENTITY);
  196.     }

  197.     /** Find a vector from two known cross products.
  198.      * <p>
  199.      * We want to find Ω such that: Ω ⨯ v₁ = c₁ and Ω ⨯ v₂ = c₂
  200.      * </p>
  201.      * <p>
  202.      * The first equation (Ω ⨯ v₁ = c₁) will always be fulfilled exactly,
  203.      * and the second one will be fulfilled if possible.
  204.      * </p>
  205.      * @param v1 vector forming the first known cross product
  206.      * @param c1 know vector for cross product Ω ⨯ v₁
  207.      * @param v2 vector forming the second known cross product
  208.      * @param c2 know vector for cross product Ω ⨯ v₂
  209.      * @param tolerance relative tolerance factor used to check singularities
  210.      * @param <T> the type of the field elements
  211.      * @return vector Ω such that: Ω ⨯ v₁ = c₁ and Ω ⨯ v₂ = c₂
  212.      * @exception MathIllegalArgumentException if vectors are inconsistent and
  213.      * no solution can be found
  214.      */
  215.     private static <T extends RealFieldElement<T>> FieldVector3D<T> inverseCrossProducts(final FieldVector3D<T> v1, final FieldVector3D<T> c1,
  216.                                                                                          final FieldVector3D<T> v2, final FieldVector3D<T> c2,
  217.                                                                                          final double tolerance)
  218.         throws MathIllegalArgumentException {

  219.         final T v12 = v1.getNormSq();
  220.         final T v1n = v12.sqrt();
  221.         final T v22 = v2.getNormSq();
  222.         final T v2n = v22.sqrt();
  223.         final T threshold;
  224.         if (v1n.getReal() >= v2n.getReal()) {
  225.             threshold = v1n.multiply(tolerance);
  226.         }
  227.         else {
  228.             threshold = v2n.multiply(tolerance);
  229.         }
  230.         FieldVector3D<T> omega = null;

  231.         try {
  232.             // create the over-determined linear system representing the two cross products
  233.             final FieldMatrix<T> m = MatrixUtils.createFieldMatrix(v12.getField(), 6, 3);
  234.             m.setEntry(0, 1, v1.getZ());
  235.             m.setEntry(0, 2, v1.getY().negate());
  236.             m.setEntry(1, 0, v1.getZ().negate());
  237.             m.setEntry(1, 2, v1.getX());
  238.             m.setEntry(2, 0, v1.getY());
  239.             m.setEntry(2, 1, v1.getX().negate());
  240.             m.setEntry(3, 1, v2.getZ());
  241.             m.setEntry(3, 2, v2.getY().negate());
  242.             m.setEntry(4, 0, v2.getZ().negate());
  243.             m.setEntry(4, 2, v2.getX());
  244.             m.setEntry(5, 0, v2.getY());
  245.             m.setEntry(5, 1, v2.getX().negate());

  246.             final T[] kk = MathArrays.buildArray(v2n.getField(), 6);
  247.             kk[0] = c1.getX();
  248.             kk[1] = c1.getY();
  249.             kk[2] = c1.getZ();
  250.             kk[3] = c2.getX();
  251.             kk[4] = c2.getY();
  252.             kk[5] = c2.getZ();
  253.             final FieldVector<T> rhs = MatrixUtils.createFieldVector(kk);

  254.             // find the best solution we can
  255.             final FieldDecompositionSolver<T> solver = new FieldQRDecomposition<>(m).getSolver();
  256.             final FieldVector<T> v = solver.solve(rhs);
  257.             omega = new FieldVector3D<>(v.getEntry(0), v.getEntry(1), v.getEntry(2));

  258.         } catch (MathIllegalArgumentException miae) {
  259.             if (miae.getSpecifier() == LocalizedCoreFormats.SINGULAR_MATRIX) {

  260.                 // handle some special cases for which we can compute a solution
  261.                 final T c12 = c1.getNormSq();
  262.                 final T c1n = c12.sqrt();
  263.                 final T c22 = c2.getNormSq();
  264.                 final T c2n = c22.sqrt();
  265.                 if (c1n.getReal() <= threshold.getReal() && c2n.getReal() <= threshold.getReal()) {
  266.                     // simple special case, velocities are cancelled
  267.                     return new FieldVector3D<>(v12.getField().getZero(), v12.getField().getZero(), v12.getField().getZero());
  268.                 } else if (v1n.getReal() <= threshold.getReal() && c1n.getReal() >= threshold.getReal()) {
  269.                     // this is inconsistent, if v₁ is zero, c₁ must be 0 too
  270.                     throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE,
  271.                                                            c1n.getReal(), 0, true);
  272.                 } else if (v2n.getReal() <= threshold.getReal() && c2n.getReal() >= threshold.getReal()) {
  273.                     // this is inconsistent, if v₂ is zero, c₂ must be 0 too
  274.                     throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE,
  275.                                                            c2n.getReal(), 0, true);
  276.                 } else if (v1.crossProduct(v1).getNorm().getReal() <= threshold.getReal() && v12.getReal() > threshold.getReal()) {
  277.                     // simple special case, v₂ is redundant with v₁, we just ignore it
  278.                     // use the simplest Ω: orthogonal to both v₁ and c₁
  279.                     omega = new FieldVector3D<>(v12.reciprocal(), v1.crossProduct(c1));
  280.                 } else {
  281.                     throw miae;
  282.                 }
  283.             } else {
  284.                 throw miae;
  285.             }
  286.         }
  287.         // check results
  288.         final T d1 = FieldVector3D.distance(omega.crossProduct(v1), c1);
  289.         if (d1.getReal() > threshold.getReal()) {
  290.             throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE, 0, true);
  291.         }

  292.         final T d2 = FieldVector3D.distance(omega.crossProduct(v2), c2);
  293.         if (d2.getReal() > threshold.getReal()) {
  294.             throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE, 0, true);
  295.         }

  296.         return omega;

  297.     }

  298.     /** Transform the instance to a {@link FieldRotation}&lt;{@link FieldDerivativeStructure}&gt;.
  299.      * <p>
  300.      * The {@link DerivativeStructure} coordinates correspond to time-derivatives up
  301.      * to the user-specified order.
  302.      * </p>
  303.      * @param order derivation order for the vector components
  304.      * @return rotation with time-derivatives embedded within the coordinates
  305.           * @since 9.2
  306.      */
  307.     public FieldRotation<FieldDerivativeStructure<T>> toDerivativeStructureRotation(final int order) {

  308.         // quaternion components
  309.         final T q0 = rotation.getQ0();
  310.         final T q1 = rotation.getQ1();
  311.         final T q2 = rotation.getQ2();
  312.         final T q3 = rotation.getQ3();

  313.         // first time-derivatives of the quaternion
  314.         final T oX    = rotationRate.getX();
  315.         final T oY    = rotationRate.getY();
  316.         final T oZ    = rotationRate.getZ();
  317.         final T q0Dot = q0.linearCombination(q1.negate(), oX, q2.negate(), oY, q3.negate(), oZ).multiply(0.5);
  318.         final T q1Dot = q0.linearCombination(q0,          oX, q3.negate(), oY, q2,          oZ).multiply(0.5);
  319.         final T q2Dot = q0.linearCombination(q3,          oX, q0,          oY, q1.negate(), oZ).multiply(0.5);
  320.         final T q3Dot = q0.linearCombination(q2.negate(), oX, q1,          oY, q0,          oZ).multiply(0.5);

  321.         // second time-derivatives of the quaternion
  322.         final T oXDot = rotationAcceleration.getX();
  323.         final T oYDot = rotationAcceleration.getY();
  324.         final T oZDot = rotationAcceleration.getZ();
  325.         final T q0DotDot = q0.linearCombination(array6(q1, q2,  q3, q1Dot, q2Dot,  q3Dot),
  326.                                                 array6(oXDot, oYDot, oZDot, oX, oY, oZ)).
  327.                            multiply(-0.5);
  328.         final T q1DotDot = q0.linearCombination(array6(q0, q2, q3.negate(), q0Dot, q2Dot, q3Dot.negate()),
  329.                                                 array6(oXDot, oZDot, oYDot, oX, oZ, oY)).multiply(0.5);
  330.         final T q2DotDot =  q0.linearCombination(array6(q0, q3, q1.negate(), q0Dot, q3Dot, q1Dot.negate()),
  331.                                                  array6(oYDot, oXDot, oZDot, oY, oX, oZ)).multiply(0.5);
  332.         final T q3DotDot =  q0.linearCombination(array6(q0, q1, q2.negate(), q0Dot, q1Dot, q2Dot.negate()),
  333.                                                  array6(oZDot, oYDot, oXDot, oZ, oY, oX)).multiply(0.5);

  334.         final FDSFactory<T> factory;
  335.         final FieldDerivativeStructure<T> q0DS;
  336.         final FieldDerivativeStructure<T> q1DS;
  337.         final FieldDerivativeStructure<T> q2DS;
  338.         final FieldDerivativeStructure<T> q3DS;
  339.         switch(order) {
  340.             case 0 :
  341.                 factory = new FDSFactory<>(q0.getField(), 1, order);
  342.                 q0DS = factory.build(q0);
  343.                 q1DS = factory.build(q1);
  344.                 q2DS = factory.build(q2);
  345.                 q3DS = factory.build(q3);
  346.                 break;
  347.             case 1 :
  348.                 factory = new FDSFactory<>(q0.getField(), 1, order);
  349.                 q0DS = factory.build(q0, q0Dot);
  350.                 q1DS = factory.build(q1, q1Dot);
  351.                 q2DS = factory.build(q2, q2Dot);
  352.                 q3DS = factory.build(q3, q3Dot);
  353.                 break;
  354.             case 2 :
  355.                 factory = new FDSFactory<>(q0.getField(), 1, order);
  356.                 q0DS = factory.build(q0, q0Dot, q0DotDot);
  357.                 q1DS = factory.build(q1, q1Dot, q1DotDot);
  358.                 q2DS = factory.build(q2, q2Dot, q2DotDot);
  359.                 q3DS = factory.build(q3, q3Dot, q3DotDot);
  360.                 break;
  361.             default :
  362.                 throw new OrekitException(OrekitMessages.OUT_OF_RANGE_DERIVATION_ORDER, order);
  363.         }

  364.         return new FieldRotation<>(q0DS, q1DS, q2DS, q3DS, false);

  365.     }

  366.     /** Build an arry of 6 elements.
  367.      * @param e1 first element
  368.      * @param e2 second element
  369.      * @param e3 third element
  370.      * @param e4 fourth element
  371.      * @param e5 fifth element
  372.      * @param e6 sixth element
  373.      * @return a new array
  374.      * @since 9.2
  375.      */
  376.     private T[] array6(final T e1, final T e2, final T e3, final T e4, final T e5, final T e6) {
  377.         final T[] array = MathArrays.buildArray(e1.getField(), 6);
  378.         array[0] = e1;
  379.         array[1] = e2;
  380.         array[2] = e3;
  381.         array[3] = e4;
  382.         array[4] = e5;
  383.         array[5] = e6;
  384.         return array;
  385.     }

  386.     /** Estimate rotation rate between two orientations.
  387.      * <p>Estimation is based on a simple fixed rate rotation
  388.      * during the time interval between the two orientations.</p>
  389.      * @param start start orientation
  390.      * @param end end orientation
  391.      * @param dt time elapsed between the dates of the two orientations
  392.      * @param <T> the type of the field elements
  393.      * @return rotation rate allowing to go from start to end orientations
  394.      */
  395.     public static <T extends RealFieldElement<T>>
  396.         FieldVector3D<T> estimateRate(final FieldRotation<T> start,
  397.                                       final FieldRotation<T> end,
  398.                                       final double dt) {
  399.         return estimateRate(start, end, start.getQ0().getField().getZero().add(dt));
  400.     }

  401.     /** Estimate rotation rate between two orientations.
  402.      * <p>Estimation is based on a simple fixed rate rotation
  403.      * during the time interval between the two orientations.</p>
  404.      * @param start start orientation
  405.      * @param end end orientation
  406.      * @param dt time elapsed between the dates of the two orientations
  407.      * @param <T> the type of the field elements
  408.      * @return rotation rate allowing to go from start to end orientations
  409.      */
  410.     public static <T extends RealFieldElement<T>>
  411.         FieldVector3D<T> estimateRate(final FieldRotation<T> start,
  412.                                       final FieldRotation<T> end,
  413.                                       final T dt) {
  414.         final FieldRotation<T> evolution = start.compose(end.revert(), RotationConvention.VECTOR_OPERATOR);
  415.         return new FieldVector3D<>(evolution.getAngle().divide(dt),
  416.                                    evolution.getAxis(RotationConvention.VECTOR_OPERATOR));
  417.     }

  418.     /**
  419.      * Revert a rotation / rotation rate / rotation acceleration triplet.
  420.      *
  421.      * <p> Build a triplet which reverse the effect of another triplet.
  422.      *
  423.      * @return a new triplet whose effect is the reverse of the effect
  424.      * of the instance
  425.      */
  426.     public FieldAngularCoordinates<T> revert() {
  427.         return new FieldAngularCoordinates<>(rotation.revert(),
  428.                                              rotation.applyInverseTo(rotationRate.negate()),
  429.                                              rotation.applyInverseTo(rotationAcceleration.negate()));
  430.     }

  431.     /** Get a time-shifted state.
  432.      * <p>
  433.      * The state can be slightly shifted to close dates. This shift is based on
  434.      * a simple quadratic model. It is <em>not</em> intended as a replacement for
  435.      * proper attitude propagation but should be sufficient for either small
  436.      * time shifts or coarse accuracy.
  437.      * </p>
  438.      * @param dt time shift in seconds
  439.      * @return a new state, shifted with respect to the instance (which is immutable)
  440.      */
  441.     public FieldAngularCoordinates<T> shiftedBy(final double dt) {
  442.         return shiftedBy(rotation.getQ0().getField().getZero().add(dt));
  443.     }

  444.     /** Get a time-shifted state.
  445.      * <p>
  446.      * The state can be slightly shifted to close dates. This shift is based on
  447.      * a simple quadratic model. It is <em>not</em> intended as a replacement for
  448.      * proper attitude propagation but should be sufficient for either small
  449.      * time shifts or coarse accuracy.
  450.      * </p>
  451.      * @param dt time shift in seconds
  452.      * @return a new state, shifted with respect to the instance (which is immutable)
  453.      */
  454.     public FieldAngularCoordinates<T> shiftedBy(final T dt) {

  455.         // the shiftedBy method is based on a local approximation.
  456.         // It considers separately the contribution of the constant
  457.         // rotation, the linear contribution or the rate and the
  458.         // quadratic contribution of the acceleration. The rate
  459.         // and acceleration contributions are small rotations as long
  460.         // as the time shift is small, which is the crux of the algorithm.
  461.         // Small rotations are almost commutative, so we append these small
  462.         // contributions one after the other, as if they really occurred
  463.         // successively, despite this is not what really happens.

  464.         // compute the linear contribution first, ignoring acceleration
  465.         // BEWARE: there is really a minus sign here, because if
  466.         // the target frame rotates in one direction, the vectors in the origin
  467.         // frame seem to rotate in the opposite direction
  468.         final T rate = rotationRate.getNorm();
  469.         final T zero = rate.getField().getZero();
  470.         final T one  = rate.getField().getOne();
  471.         final FieldRotation<T> rateContribution = (rate.getReal() == 0.0) ?
  472.                                                   new FieldRotation<>(one, zero, zero, zero, false) :
  473.                                                   new FieldRotation<>(rotationRate,
  474.                                                                       rate.multiply(dt),
  475.                                                                       RotationConvention.FRAME_TRANSFORM);

  476.         // append rotation and rate contribution
  477.         final FieldAngularCoordinates<T> linearPart =
  478.                 new FieldAngularCoordinates<>(rateContribution.compose(rotation, RotationConvention.VECTOR_OPERATOR),
  479.                                               rotationRate);

  480.         final T acc  = rotationAcceleration.getNorm();
  481.         if (acc.getReal() == 0.0) {
  482.             // no acceleration, the linear part is sufficient
  483.             return linearPart;
  484.         }

  485.         // compute the quadratic contribution, ignoring initial rotation and rotation rate
  486.         // BEWARE: there is really a minus sign here, because if
  487.         // the target frame rotates in one direction, the vectors in the origin
  488.         // frame seem to rotate in the opposite direction
  489.         final FieldAngularCoordinates<T> quadraticContribution =
  490.                 new FieldAngularCoordinates<>(new FieldRotation<>(rotationAcceleration,
  491.                                                                   acc.multiply(dt.multiply(0.5).multiply(dt)),
  492.                                                                   RotationConvention.FRAME_TRANSFORM),
  493.                                               new FieldVector3D<>(dt, rotationAcceleration),
  494.                                               rotationAcceleration);

  495.         // the quadratic contribution is a small rotation:
  496.         // its initial angle and angular rate are both zero.
  497.         // small rotations are almost commutative, so we append the small
  498.         // quadratic part after the linear part as a simple offset
  499.         return quadraticContribution.addOffset(linearPart);

  500.     }

  501.     /** Get the rotation.
  502.      * @return the rotation.
  503.      */
  504.     public FieldRotation<T> getRotation() {
  505.         return rotation;
  506.     }

  507.     /** Get the rotation rate.
  508.      * @return the rotation rate vector (rad/s).
  509.      */
  510.     public FieldVector3D<T> getRotationRate() {
  511.         return rotationRate;
  512.     }

  513.     /** Get the rotation acceleration.
  514.      * @return the rotation acceleration vector dΩ/dt (rad²/s²).
  515.      */
  516.     public FieldVector3D<T> getRotationAcceleration() {
  517.         return rotationAcceleration;
  518.     }

  519.     /** Add an offset from the instance.
  520.      * <p>
  521.      * We consider here that the offset rotation is applied first and the
  522.      * instance is applied afterward. Note that angular coordinates do <em>not</em>
  523.      * commute under this operation, i.e. {@code a.addOffset(b)} and {@code
  524.      * b.addOffset(a)} lead to <em>different</em> results in most cases.
  525.      * </p>
  526.      * <p>
  527.      * The two methods {@link #addOffset(FieldAngularCoordinates) addOffset} and
  528.      * {@link #subtractOffset(FieldAngularCoordinates) subtractOffset} are designed
  529.      * so that round trip applications are possible. This means that both {@code
  530.      * ac1.subtractOffset(ac2).addOffset(ac2)} and {@code
  531.      * ac1.addOffset(ac2).subtractOffset(ac2)} return angular coordinates equal to ac1.
  532.      * </p>
  533.      * @param offset offset to subtract
  534.      * @return new instance, with offset subtracted
  535.      * @see #subtractOffset(FieldAngularCoordinates)
  536.      */
  537.     public FieldAngularCoordinates<T> addOffset(final FieldAngularCoordinates<T> offset) {
  538.         final FieldVector3D<T> rOmega    = rotation.applyTo(offset.rotationRate);
  539.         final FieldVector3D<T> rOmegaDot = rotation.applyTo(offset.rotationAcceleration);
  540.         return new FieldAngularCoordinates<>(rotation.compose(offset.rotation, RotationConvention.VECTOR_OPERATOR),
  541.                                              rotationRate.add(rOmega),
  542.                                              new FieldVector3D<>( 1.0, rotationAcceleration,
  543.                                                                   1.0, rOmegaDot,
  544.                                                                  -1.0, FieldVector3D.crossProduct(rotationRate, rOmega)));
  545.     }

  546.     /** Subtract an offset from the instance.
  547.      * <p>
  548.      * We consider here that the offset Rotation is applied first and the
  549.      * instance is applied afterward. Note that angular coordinates do <em>not</em>
  550.      * commute under this operation, i.e. {@code a.subtractOffset(b)} and {@code
  551.      * b.subtractOffset(a)} lead to <em>different</em> results in most cases.
  552.      * </p>
  553.      * <p>
  554.      * The two methods {@link #addOffset(FieldAngularCoordinates) addOffset} and
  555.      * {@link #subtractOffset(FieldAngularCoordinates) subtractOffset} are designed
  556.      * so that round trip applications are possible. This means that both {@code
  557.      * ac1.subtractOffset(ac2).addOffset(ac2)} and {@code
  558.      * ac1.addOffset(ac2).subtractOffset(ac2)} return angular coordinates equal to ac1.
  559.      * </p>
  560.      * @param offset offset to subtract
  561.      * @return new instance, with offset subtracted
  562.      * @see #addOffset(FieldAngularCoordinates)
  563.      */
  564.     public FieldAngularCoordinates<T> subtractOffset(final FieldAngularCoordinates<T> offset) {
  565.         return addOffset(offset.revert());
  566.     }

  567.     /** Convert to a regular angular coordinates.
  568.      * @return a regular angular coordinates
  569.      */
  570.     public AngularCoordinates toAngularCoordinates() {
  571.         return new AngularCoordinates(rotation.toRotation(), rotationRate.toVector3D(),
  572.                                       rotationAcceleration.toVector3D());
  573.     }

  574.     /** Apply the rotation to a pv coordinates.
  575.      * @param pv vector to apply the rotation to
  576.      * @return a new pv coordinates which is the image of u by the rotation
  577.      */
  578.     public FieldPVCoordinates<T> applyTo(final PVCoordinates pv) {

  579.         final FieldVector3D<T> transformedP = rotation.applyTo(pv.getPosition());
  580.         final FieldVector3D<T> crossP       = FieldVector3D.crossProduct(rotationRate, transformedP);
  581.         final FieldVector3D<T> transformedV = rotation.applyTo(pv.getVelocity()).subtract(crossP);
  582.         final FieldVector3D<T> crossV       = FieldVector3D.crossProduct(rotationRate, transformedV);
  583.         final FieldVector3D<T> crossCrossP  = FieldVector3D.crossProduct(rotationRate, crossP);
  584.         final FieldVector3D<T> crossDotP    = FieldVector3D.crossProduct(rotationAcceleration, transformedP);
  585.         final FieldVector3D<T> transformedA = new FieldVector3D<>( 1, rotation.applyTo(pv.getAcceleration()),
  586.                                                                   -2, crossV,
  587.                                                                   -1, crossCrossP,
  588.                                                                   -1, crossDotP);

  589.         return new FieldPVCoordinates<>(transformedP, transformedV, transformedA);

  590.     }

  591.     /** Apply the rotation to a pv coordinates.
  592.      * @param pv vector to apply the rotation to
  593.      * @return a new pv coordinates which is the image of u by the rotation
  594.      */
  595.     public TimeStampedFieldPVCoordinates<T> applyTo(final TimeStampedPVCoordinates pv) {

  596.         final FieldVector3D<T> transformedP = rotation.applyTo(pv.getPosition());
  597.         final FieldVector3D<T> crossP       = FieldVector3D.crossProduct(rotationRate, transformedP);
  598.         final FieldVector3D<T> transformedV = rotation.applyTo(pv.getVelocity()).subtract(crossP);
  599.         final FieldVector3D<T> crossV       = FieldVector3D.crossProduct(rotationRate, transformedV);
  600.         final FieldVector3D<T> crossCrossP  = FieldVector3D.crossProduct(rotationRate, crossP);
  601.         final FieldVector3D<T> crossDotP    = FieldVector3D.crossProduct(rotationAcceleration, transformedP);
  602.         final FieldVector3D<T> transformedA = new FieldVector3D<>( 1, rotation.applyTo(pv.getAcceleration()),
  603.                                                                   -2, crossV,
  604.                                                                   -1, crossCrossP,
  605.                                                                   -1, crossDotP);

  606.         return new TimeStampedFieldPVCoordinates<>(pv.getDate(), transformedP, transformedV, transformedA);

  607.     }

  608.     /** Apply the rotation to a pv coordinates.
  609.      * @param pv vector to apply the rotation to
  610.      * @return a new pv coordinates which is the image of u by the rotation
  611.      * @since 9.0
  612.      */
  613.     public FieldPVCoordinates<T> applyTo(final FieldPVCoordinates<T> pv) {

  614.         final FieldVector3D<T> transformedP = rotation.applyTo(pv.getPosition());
  615.         final FieldVector3D<T> crossP       = FieldVector3D.crossProduct(rotationRate, transformedP);
  616.         final FieldVector3D<T> transformedV = rotation.applyTo(pv.getVelocity()).subtract(crossP);
  617.         final FieldVector3D<T> crossV       = FieldVector3D.crossProduct(rotationRate, transformedV);
  618.         final FieldVector3D<T> crossCrossP  = FieldVector3D.crossProduct(rotationRate, crossP);
  619.         final FieldVector3D<T> crossDotP    = FieldVector3D.crossProduct(rotationAcceleration, transformedP);
  620.         final FieldVector3D<T> transformedA = new FieldVector3D<>( 1, rotation.applyTo(pv.getAcceleration()),
  621.                                                                   -2, crossV,
  622.                                                                   -1, crossCrossP,
  623.                                                                   -1, crossDotP);

  624.         return new FieldPVCoordinates<>(transformedP, transformedV, transformedA);

  625.     }

  626.     /** Apply the rotation to a pv coordinates.
  627.      * @param pv vector to apply the rotation to
  628.      * @return a new pv coordinates which is the image of u by the rotation
  629.      * @since 9.0
  630.      */
  631.     public TimeStampedFieldPVCoordinates<T> applyTo(final TimeStampedFieldPVCoordinates<T> pv) {

  632.         final FieldVector3D<T> transformedP = rotation.applyTo(pv.getPosition());
  633.         final FieldVector3D<T> crossP       = FieldVector3D.crossProduct(rotationRate, transformedP);
  634.         final FieldVector3D<T> transformedV = rotation.applyTo(pv.getVelocity()).subtract(crossP);
  635.         final FieldVector3D<T> crossV       = FieldVector3D.crossProduct(rotationRate, transformedV);
  636.         final FieldVector3D<T> crossCrossP  = FieldVector3D.crossProduct(rotationRate, crossP);
  637.         final FieldVector3D<T> crossDotP    = FieldVector3D.crossProduct(rotationAcceleration, transformedP);
  638.         final FieldVector3D<T> transformedA = new FieldVector3D<>( 1, rotation.applyTo(pv.getAcceleration()),
  639.                                                                   -2, crossV,
  640.                                                                   -1, crossCrossP,
  641.                                                                   -1, crossDotP);

  642.         return new TimeStampedFieldPVCoordinates<>(pv.getDate(), transformedP, transformedV, transformedA);

  643.     }

  644.     /** Convert rotation, rate and acceleration to modified Rodrigues vector and derivatives.
  645.      * <p>
  646.      * The modified Rodrigues vector is tan(θ/4) u where θ and u are the
  647.      * rotation angle and axis respectively.
  648.      * </p>
  649.      * @param sign multiplicative sign for quaternion components
  650.      * @return modified Rodrigues vector and derivatives (vector on row 0, first derivative
  651.      * on row 1, second derivative on row 2)
  652.      * @see #createFromModifiedRodrigues(RealFieldElement[][])
  653.      * @since 9.0
  654.      */
  655.     public T[][] getModifiedRodrigues(final double sign) {

  656.         final T q0    = getRotation().getQ0().multiply(sign);
  657.         final T q1    = getRotation().getQ1().multiply(sign);
  658.         final T q2    = getRotation().getQ2().multiply(sign);
  659.         final T q3    = getRotation().getQ3().multiply(sign);
  660.         final T oX    = getRotationRate().getX();
  661.         final T oY    = getRotationRate().getY();
  662.         final T oZ    = getRotationRate().getZ();
  663.         final T oXDot = getRotationAcceleration().getX();
  664.         final T oYDot = getRotationAcceleration().getY();
  665.         final T oZDot = getRotationAcceleration().getZ();

  666.         // first time-derivatives of the quaternion
  667.         final T q0Dot = q0.linearCombination(q1.negate(), oX, q2.negate(), oY, q3.negate(), oZ).multiply(0.5);
  668.         final T q1Dot = q0.linearCombination( q0, oX, q3.negate(), oY,  q2, oZ).multiply(0.5);
  669.         final T q2Dot = q0.linearCombination( q3, oX,  q0, oY, q1.negate(), oZ).multiply(0.5);
  670.         final T q3Dot = q0.linearCombination(q2.negate(), oX,  q1, oY,  q0, oZ).multiply(0.5);

  671.         // second time-derivatives of the quaternion
  672.         final T q0DotDot = linearCombination(q1, oXDot, q2, oYDot, q3, oZDot,
  673.                                              q1Dot, oX, q2Dot, oY, q3Dot, oZ).
  674.                            multiply(-0.5);
  675.         final T q1DotDot = linearCombination(q0, oXDot, q2, oZDot, q3.negate(), oYDot,
  676.                                              q0Dot, oX, q2Dot, oZ, q3Dot.negate(), oY).
  677.                            multiply(0.5);
  678.         final T q2DotDot = linearCombination(q0, oYDot, q3, oXDot, q1.negate(), oZDot,
  679.                                              q0Dot, oY, q3Dot, oX, q1Dot.negate(), oZ).
  680.                            multiply(0.5);
  681.         final T q3DotDot = linearCombination(q0, oZDot, q1, oYDot, q2.negate(), oXDot,
  682.                                              q0Dot, oZ, q1Dot, oY, q2Dot.negate(), oX).
  683.                            multiply(0.5);

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

  690.         final T r1       = inv.multiply(q1);
  691.         final T r2       = inv.multiply(q2);
  692.         final T r3       = inv.multiply(q3);

  693.         final T mInvR1   = inv.multiply(r1).negate();
  694.         final T mInvR2   = inv.multiply(r2).negate();
  695.         final T mInvR3   = inv.multiply(r3).negate();

  696.         final T r1Dot    = q0.linearCombination(inv, q1Dot, mInvR1, q0Dot);
  697.         final T r2Dot    = q0.linearCombination(inv, q2Dot, mInvR2, q0Dot);
  698.         final T r3Dot    = q0.linearCombination(inv, q3Dot, mInvR3, q0Dot);

  699.         final T r1DotDot = q0.linearCombination(inv, q1DotDot, mTwoInvQ0Dot, r1Dot, mInvR1, q0DotDot);
  700.         final T r2DotDot = q0.linearCombination(inv, q2DotDot, mTwoInvQ0Dot, r2Dot, mInvR2, q0DotDot);
  701.         final T r3DotDot = q0.linearCombination(inv, q3DotDot, mTwoInvQ0Dot, r3Dot, mInvR3, q0DotDot);

  702.         final T[][] rodrigues = MathArrays.buildArray(q0.getField(), 3, 3);
  703.         rodrigues[0][0] = r1;
  704.         rodrigues[0][1] = r2;
  705.         rodrigues[0][2] = r3;
  706.         rodrigues[1][0] = r1Dot;
  707.         rodrigues[1][1] = r2Dot;
  708.         rodrigues[1][2] = r3Dot;
  709.         rodrigues[2][0] = r1DotDot;
  710.         rodrigues[2][1] = r2DotDot;
  711.         rodrigues[2][2] = r3DotDot;
  712.         return rodrigues;

  713.     }

  714.     /**
  715.      * Compute a linear combination.
  716.      * @param a1 first factor of the first term
  717.      * @param b1 second factor of the first term
  718.      * @param a2 first factor of the second term
  719.      * @param b2 second factor of the second term
  720.      * @param a3 first factor of the third term
  721.      * @param b3 second factor of the third term
  722.      * @param a4 first factor of the fourth term
  723.      * @param b4 second factor of the fourth term
  724.      * @param a5 first factor of the fifth term
  725.      * @param b5 second factor of the fifth term
  726.      * @param a6 first factor of the sixth term
  727.      * @param b6 second factor of the sicth term
  728.      * @return a<sub>1</sub>&times;b<sub>1</sub> + a<sub>2</sub>&times;b<sub>2</sub> +
  729.      * a<sub>3</sub>&times;b<sub>3</sub> + a<sub>4</sub>&times;b<sub>4</sub> +
  730.      * a<sub>5</sub>&times;b<sub>5</sub> + a<sub>6</sub>&times;b<sub>6</sub>
  731.      */
  732.     private T linearCombination(final T a1, final T b1, final T a2, final T b2, final T a3, final T b3,
  733.                                 final T a4, final T b4, final T a5, final T b5, final T a6, final T b6) {

  734.         final T[] a = MathArrays.buildArray(a1.getField(), 6);
  735.         a[0] = a1;
  736.         a[1] = a2;
  737.         a[2] = a3;
  738.         a[3] = a4;
  739.         a[4] = a5;
  740.         a[5] = a6;

  741.         final T[] b = MathArrays.buildArray(b1.getField(), 6);
  742.         b[0] = b1;
  743.         b[1] = b2;
  744.         b[2] = b3;
  745.         b[3] = b4;
  746.         b[4] = b5;
  747.         b[5] = b6;

  748.         return a1.linearCombination(a, b);

  749.     }

  750.     /** Convert a modified Rodrigues vector and derivatives to angular coordinates.
  751.      * @param r modified Rodrigues vector (with first and second times derivatives)
  752.      * @param <T> the type of the field elements
  753.      * @return angular coordinates
  754.      * @see #getModifiedRodrigues(double)
  755.      * @since 9.0
  756.      */
  757.     public static <T extends RealFieldElement<T>>  FieldAngularCoordinates<T> createFromModifiedRodrigues(final T[][] r) {

  758.         // rotation
  759.         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]));
  760.         final T oPQ0     = rSquared.add(1).reciprocal().multiply(2);
  761.         final T q0       = oPQ0.subtract(1);
  762.         final T q1       = oPQ0.multiply(r[0][0]);
  763.         final T q2       = oPQ0.multiply(r[0][1]);
  764.         final T q3       = oPQ0.multiply(r[0][2]);

  765.         // rotation rate
  766.         final T oPQ02    = oPQ0.multiply(oPQ0);
  767.         final T q0Dot    = oPQ02.multiply(q0.linearCombination(r[0][0], r[1][0], r[0][1], r[1][1],  r[0][2], r[1][2])).negate();
  768.         final T q1Dot    = oPQ0.multiply(r[1][0]).add(r[0][0].multiply(q0Dot));
  769.         final T q2Dot    = oPQ0.multiply(r[1][1]).add(r[0][1].multiply(q0Dot));
  770.         final T q3Dot    = oPQ0.multiply(r[1][2]).add(r[0][2].multiply(q0Dot));
  771.         final T oX       = q0.linearCombination(q1.negate(), q0Dot,  q0, q1Dot,  q3, q2Dot, q2.negate(), q3Dot).multiply(2);
  772.         final T oY       = q0.linearCombination(q2.negate(), q0Dot, q3.negate(), q1Dot,  q0, q2Dot,  q1, q3Dot).multiply(2);
  773.         final T oZ       = q0.linearCombination(q3.negate(), q0Dot,  q2, q1Dot, q1.negate(), q2Dot,  q0, q3Dot).multiply(2);

  774.         // rotation acceleration
  775.         final T q0DotDot = q0.subtract(1).negate().divide(oPQ0).multiply(q0Dot).multiply(q0Dot).
  776.                            subtract(oPQ02.multiply(q0.linearCombination(r[0][0], r[2][0], r[0][1], r[2][1], r[0][2], r[2][2]))).
  777.                            subtract(q1Dot.multiply(q1Dot).add(q2Dot.multiply(q2Dot)).add(q3Dot.multiply(q3Dot)));
  778.         final T q1DotDot = q0.linearCombination(oPQ0, r[2][0], r[1][0].add(r[1][0]), q0Dot, r[0][0], q0DotDot);
  779.         final T q2DotDot = q0.linearCombination(oPQ0, r[2][1], r[1][1].add(r[1][1]), q0Dot, r[0][1], q0DotDot);
  780.         final T q3DotDot = q0.linearCombination(oPQ0, r[2][2], r[1][2].add(r[1][2]), q0Dot, r[0][2], q0DotDot);
  781.         final T oXDot    = q0.linearCombination(q1.negate(), q0DotDot,  q0, q1DotDot,  q3, q2DotDot, q2.negate(), q3DotDot).multiply(2);
  782.         final T oYDot    = q0.linearCombination(q2.negate(), q0DotDot, q3.negate(), q1DotDot,  q0, q2DotDot,  q1, q3DotDot).multiply(2);
  783.         final T oZDot    = q0.linearCombination(q3.negate(), q0DotDot,  q2, q1DotDot, q1.negate(), q2DotDot,  q0, q3DotDot).multiply(2);

  784.         return new FieldAngularCoordinates<>(new FieldRotation<>(q0, q1, q2, q3, false),
  785.                                              new FieldVector3D<>(oX, oY, oZ),
  786.                                              new FieldVector3D<>(oXDot, oYDot, oZDot));

  787.     }

  788. }