Transform.java

  1. /* Copyright 2002-2022 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.frames;

  18. import java.io.Serializable;
  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21. import java.util.Collection;
  22. import java.util.List;
  23. import java.util.stream.Collectors;
  24. import java.util.stream.Stream;

  25. import org.hipparchus.CalculusFieldElement;
  26. import org.hipparchus.geometry.euclidean.threed.Line;
  27. import org.hipparchus.geometry.euclidean.threed.Rotation;
  28. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.TimeInterpolable;
  31. import org.orekit.time.TimeShiftable;
  32. import org.orekit.utils.AngularCoordinates;
  33. import org.orekit.utils.AngularDerivativesFilter;
  34. import org.orekit.utils.CartesianDerivativesFilter;
  35. import org.orekit.utils.FieldPVCoordinates;
  36. import org.orekit.utils.PVCoordinates;
  37. import org.orekit.utils.TimeStampedAngularCoordinates;
  38. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  39. import org.orekit.utils.TimeStampedPVCoordinates;


  40. /** Transformation class in three dimensional space.
  41.  *
  42.  * <p>This class represents the transformation engine between {@link Frame frames}.
  43.  * It is used both to define the relationship between each frame and its
  44.  * parent frame and to gather all individual transforms into one
  45.  * operation when converting between frames far away from each other.</p>
  46.  * <p> The convention used in OREKIT is vectorial transformation. It means
  47.  * that a transformation is defined as a transform to apply to the
  48.  * coordinates of a vector expressed in the old frame to obtain the
  49.  * same vector expressed in the new frame.
  50.  *
  51.  * <p>Instances of this class are guaranteed to be immutable.</p>
  52.  *
  53.  * <h2> Examples </h2>
  54.  *
  55.  * <h3> Example of translation from R<sub>A</sub> to R<sub>B</sub> </h3>
  56.  *
  57.  * <p> We want to transform the {@link PVCoordinates} PV<sub>A</sub> to
  58.  * PV<sub>B</sub> with :
  59.  * <p> PV<sub>A</sub> = ({1, 0, 0}, {2, 0, 0}, {3, 0, 0}); <br>
  60.  *     PV<sub>B</sub> = ({0, 0, 0}, {0, 0, 0}, {0, 0, 0});
  61.  *
  62.  * <p> The transform to apply then is defined as follows :
  63.  *
  64.  * <pre><code>
  65.  * Vector3D translation  = new Vector3D(-1, 0, 0);
  66.  * Vector3D velocity     = new Vector3D(-2, 0, 0);
  67.  * Vector3D acceleration = new Vector3D(-3, 0, 0);
  68.  *
  69.  * Transform R1toR2 = new Transform(date, translation, velocity, acceleration);
  70.  *
  71.  * PVB = R1toR2.transformPVCoordinates(PVA);
  72.  * </code></pre>
  73.  *
  74.  * <h3> Example of rotation from R<sub>A</sub> to R<sub>B</sub> </h3>
  75.  * <p> We want to transform the {@link PVCoordinates} PV<sub>A</sub> to
  76.  * PV<sub>B</sub> with
  77.  *
  78.  * <p> PV<sub>A</sub> = ({1, 0, 0}, { 1, 0, 0}); <br>
  79.  *     PV<sub>B</sub> = ({0, 1, 0}, {-2, 1, 0});
  80.  *
  81.  * <p> The transform to apply then is defined as follows :
  82.  *
  83.  * <pre><code>
  84.  * Rotation rotation = new Rotation(Vector3D.PLUS_K, FastMath.PI / 2);
  85.  * Vector3D rotationRate = new Vector3D(0, 0, -2);
  86.  *
  87.  * Transform R1toR2 = new Transform(rotation, rotationRate);
  88.  *
  89.  * PVB = R1toR2.transformPVCoordinates(PVA);
  90.  * </code></pre>
  91.  *
  92.  * @author Luc Maisonobe
  93.  * @author Fabien Maussion
  94.  */
  95. public class Transform implements
  96.         TimeInterpolable<Transform>,
  97.         TimeShiftable<Transform>,
  98.         Serializable,
  99.         StaticTransform {

  100.     /** Identity transform. */
  101.     public static final Transform IDENTITY = new IdentityTransform();

  102.     /** Serializable UID. */
  103.     private static final long serialVersionUID = 210140410L;

  104.     /** Date of the transform. */
  105.     private final AbsoluteDate date;

  106.     /** Cartesian coordinates of the target frame with respect to the original frame. */
  107.     private final PVCoordinates cartesian;

  108.     /** Angular coordinates of the target frame with respect to the original frame. */
  109.     private final AngularCoordinates angular;

  110.     /** Build a transform from its primitive operations.
  111.      * @param date date of the transform
  112.      * @param cartesian Cartesian coordinates of the target frame with respect to the original frame
  113.      * @param angular angular coordinates of the target frame with respect to the original frame
  114.      */
  115.     private Transform(final AbsoluteDate date,
  116.                       final PVCoordinates cartesian, final AngularCoordinates angular) {
  117.         this.date      = date;
  118.         this.cartesian = cartesian;
  119.         this.angular   = angular;
  120.     }

  121.     /** Build a translation transform.
  122.      * @param date date of the transform
  123.      * @param translation translation to apply (i.e. coordinates of
  124.      * the transformed origin, or coordinates of the origin of the
  125.      * old frame in the new frame)
  126.      */
  127.     public Transform(final AbsoluteDate date, final Vector3D translation) {
  128.         this(date,
  129.              new PVCoordinates(translation),
  130.              AngularCoordinates.IDENTITY);
  131.     }

  132.     /** Build a rotation transform.
  133.      * @param date date of the transform
  134.      * @param rotation rotation to apply ( i.e. rotation to apply to the
  135.      * coordinates of a vector expressed in the old frame to obtain the
  136.      * same vector expressed in the new frame )
  137.      */
  138.     public Transform(final AbsoluteDate date, final Rotation rotation) {
  139.         this(date,
  140.              PVCoordinates.ZERO,
  141.              new AngularCoordinates(rotation));
  142.     }

  143.     /** Build a translation transform, with its first time derivative.
  144.      * @param date date of the transform
  145.      * @param translation translation to apply (i.e. coordinates of
  146.      * the transformed origin, or coordinates of the origin of the
  147.      * old frame in the new frame)
  148.      * @param velocity the velocity of the translation (i.e. origin
  149.      * of the old frame velocity in the new frame)
  150.      */
  151.     public Transform(final AbsoluteDate date, final Vector3D translation,
  152.                      final Vector3D velocity) {
  153.         this(date,
  154.              new PVCoordinates(translation, velocity, Vector3D.ZERO),
  155.              AngularCoordinates.IDENTITY);
  156.     }

  157.     /** Build a translation transform, with its first and second time derivatives.
  158.      * @param date date of the transform
  159.      * @param translation translation to apply (i.e. coordinates of
  160.      * the transformed origin, or coordinates of the origin of the
  161.      * old frame in the new frame)
  162.      * @param velocity the velocity of the translation (i.e. origin
  163.      * of the old frame velocity in the new frame)
  164.      * @param acceleration the acceleration of the translation (i.e. origin
  165.      * of the old frame acceleration in the new frame)
  166.      */
  167.     public Transform(final AbsoluteDate date, final Vector3D translation,
  168.                      final Vector3D velocity, final Vector3D acceleration) {
  169.         this(date,
  170.              new PVCoordinates(translation, velocity, acceleration),
  171.              AngularCoordinates.IDENTITY);
  172.     }

  173.     /** Build a translation transform, with its first time derivative.
  174.      * @param date date of the transform
  175.      * @param cartesian Cartesian part of the transformation to apply (i.e. coordinates of
  176.      * the transformed origin, or coordinates of the origin of the
  177.      * old frame in the new frame, with their derivatives)
  178.      */
  179.     public Transform(final AbsoluteDate date, final PVCoordinates cartesian) {
  180.         this(date,
  181.              cartesian,
  182.              AngularCoordinates.IDENTITY);
  183.     }

  184.     /** Build a rotation transform.
  185.      * @param date date of the transform
  186.      * @param rotation rotation to apply ( i.e. rotation to apply to the
  187.      * coordinates of a vector expressed in the old frame to obtain the
  188.      * same vector expressed in the new frame )
  189.      * @param rotationRate the axis of the instant rotation
  190.      * expressed in the new frame. (norm representing angular rate)
  191.      */
  192.     public Transform(final AbsoluteDate date, final Rotation rotation, final Vector3D rotationRate) {
  193.         this(date,
  194.              PVCoordinates.ZERO,
  195.              new AngularCoordinates(rotation, rotationRate, Vector3D.ZERO));
  196.     }

  197.     /** Build a rotation transform.
  198.      * @param date date of the transform
  199.      * @param rotation rotation to apply ( i.e. rotation to apply to the
  200.      * coordinates of a vector expressed in the old frame to obtain the
  201.      * same vector expressed in the new frame )
  202.      * @param rotationRate the axis of the instant rotation
  203.      * @param rotationAcceleration the axis of the instant rotation
  204.      * expressed in the new frame. (norm representing angular rate)
  205.      */
  206.     public Transform(final AbsoluteDate date, final Rotation rotation, final Vector3D rotationRate,
  207.                      final Vector3D rotationAcceleration) {
  208.         this(date,
  209.              PVCoordinates.ZERO,
  210.              new AngularCoordinates(rotation, rotationRate, rotationAcceleration));
  211.     }

  212.     /** Build a rotation transform.
  213.      * @param date date of the transform
  214.      * @param angular angular part of the transformation to apply (i.e. rotation to
  215.      * apply to the coordinates of a vector expressed in the old frame to obtain the
  216.      * same vector expressed in the new frame, with its rotation rate)
  217.      */
  218.     public Transform(final AbsoluteDate date, final AngularCoordinates angular) {
  219.         this(date, PVCoordinates.ZERO, angular);
  220.     }

  221.     /** Build a transform by combining two existing ones.
  222.      * <p>
  223.      * Note that the dates of the two existing transformed are <em>ignored</em>,
  224.      * and the combined transform date is set to the date supplied in this constructor
  225.      * without any attempt to shift the raw transforms. This is a design choice allowing
  226.      * user full control of the combination.
  227.      * </p>
  228.      * @param date date of the transform
  229.      * @param first first transform applied
  230.      * @param second second transform applied
  231.      */
  232.     public Transform(final AbsoluteDate date, final Transform first, final Transform second) {
  233.         this(date,
  234.              new PVCoordinates(StaticTransform.compositeTranslation(first, second),
  235.                                compositeVelocity(first, second),
  236.                                compositeAcceleration(first, second)),
  237.              new AngularCoordinates(StaticTransform.compositeRotation(first, second),
  238.                                     compositeRotationRate(first, second),
  239.                                     compositeRotationAcceleration(first, second)));
  240.     }

  241.     /** Compute a composite velocity.
  242.      * @param first first applied transform
  243.      * @param second second applied transform
  244.      * @return velocity part of the composite transform
  245.      */
  246.     private static Vector3D compositeVelocity(final Transform first, final Transform second) {

  247.         final Vector3D v1 = first.cartesian.getVelocity();
  248.         final Rotation r1 = first.angular.getRotation();
  249.         final Vector3D o1 = first.angular.getRotationRate();
  250.         final Vector3D p2 = second.cartesian.getPosition();
  251.         final Vector3D v2 = second.cartesian.getVelocity();

  252.         final Vector3D crossP = Vector3D.crossProduct(o1, p2);

  253.         return v1.add(r1.applyInverseTo(v2.add(crossP)));

  254.     }

  255.     /** Compute a composite acceleration.
  256.      * @param first first applied transform
  257.      * @param second second applied transform
  258.      * @return acceleration part of the composite transform
  259.      */
  260.     private static Vector3D compositeAcceleration(final Transform first, final Transform second) {

  261.         final Vector3D a1    = first.cartesian.getAcceleration();
  262.         final Rotation r1    = first.angular.getRotation();
  263.         final Vector3D o1    = first.angular.getRotationRate();
  264.         final Vector3D oDot1 = first.angular.getRotationAcceleration();
  265.         final Vector3D p2    = second.cartesian.getPosition();
  266.         final Vector3D v2    = second.cartesian.getVelocity();
  267.         final Vector3D a2    = second.cartesian.getAcceleration();

  268.         final Vector3D crossCrossP = Vector3D.crossProduct(o1,    Vector3D.crossProduct(o1, p2));
  269.         final Vector3D crossV      = Vector3D.crossProduct(o1,    v2);
  270.         final Vector3D crossDotP   = Vector3D.crossProduct(oDot1, p2);

  271.         return a1.add(r1.applyInverseTo(new Vector3D(1, a2, 2, crossV, 1, crossCrossP, 1, crossDotP)));

  272.     }

  273.     /** Compute a composite rotation rate.
  274.      * @param first first applied transform
  275.      * @param second second applied transform
  276.      * @return rotation rate part of the composite transform
  277.      */
  278.     private static Vector3D compositeRotationRate(final Transform first, final Transform second) {

  279.         final Vector3D o1 = first.angular.getRotationRate();
  280.         final Rotation r2 = second.angular.getRotation();
  281.         final Vector3D o2 = second.angular.getRotationRate();

  282.         return o2.add(r2.applyTo(o1));

  283.     }

  284.     /** Compute a composite rotation acceleration.
  285.      * @param first first applied transform
  286.      * @param second second applied transform
  287.      * @return rotation acceleration part of the composite transform
  288.      */
  289.     private static Vector3D compositeRotationAcceleration(final Transform first, final Transform second) {

  290.         final Vector3D o1    = first.angular.getRotationRate();
  291.         final Vector3D oDot1 = first.angular.getRotationAcceleration();
  292.         final Rotation r2    = second.angular.getRotation();
  293.         final Vector3D o2    = second.angular.getRotationRate();
  294.         final Vector3D oDot2 = second.angular.getRotationAcceleration();

  295.         return new Vector3D( 1, oDot2,
  296.                              1, r2.applyTo(oDot1),
  297.                             -1, Vector3D.crossProduct(o2, r2.applyTo(o1)));

  298.     }

  299.     /** {@inheritDoc} */
  300.     public AbsoluteDate getDate() {
  301.         return date;
  302.     }

  303.     /** {@inheritDoc} */
  304.     public Transform shiftedBy(final double dt) {
  305.         return new Transform(date.shiftedBy(dt), cartesian.shiftedBy(dt), angular.shiftedBy(dt));
  306.     }

  307.     /**
  308.      * Shift the transform in time considering all rates, then return only the
  309.      * translation and rotation portion of the transform.
  310.      *
  311.      * @param dt time shift in seconds.
  312.      * @return shifted transform as a static transform. It is static in the
  313.      * sense that it can only be used to transform directions and positions, but
  314.      * not velocities or accelerations.
  315.      * @see #shiftedBy(double)
  316.      */
  317.     public StaticTransform staticShiftedBy(final double dt) {
  318.         return StaticTransform.of(
  319.                 date.shiftedBy(dt),
  320.                 cartesian.positionShiftedBy(dt),
  321.                 angular.rotationShiftedBy(dt));
  322.     }

  323.     /** {@inheritDoc}
  324.      * <p>
  325.      * Calling this method is equivalent to call {@link #interpolate(AbsoluteDate,
  326.      * CartesianDerivativesFilter, AngularDerivativesFilter, Collection)} with {@code cFilter}
  327.      * set to {@link CartesianDerivativesFilter#USE_PVA} and {@code aFilter} set to
  328.      * {@link AngularDerivativesFilter#USE_RRA}
  329.      * set to true.
  330.      * </p>
  331.      */
  332.     public Transform interpolate(final AbsoluteDate interpolationDate, final Stream<Transform> sample) {
  333.         return interpolate(interpolationDate,
  334.                            CartesianDerivativesFilter.USE_PVA, AngularDerivativesFilter.USE_RRA,
  335.                            sample.collect(Collectors.toList()));
  336.     }

  337.     /** Interpolate a transform from a sample set of existing transforms.
  338.      * <p>
  339.      * Note that even if first time derivatives (velocities and rotation rates)
  340.      * from sample can be ignored, the interpolated instance always includes
  341.      * interpolated derivatives. This feature can be used explicitly to
  342.      * compute these derivatives when it would be too complex to compute them
  343.      * from an analytical formula: just compute a few sample points from the
  344.      * explicit formula and set the derivatives to zero in these sample points,
  345.      * then use interpolation to add derivatives consistent with the positions
  346.      * and rotations.
  347.      * </p>
  348.      * <p>
  349.      * As this implementation of interpolation is polynomial, it should be used only
  350.      * with small samples (about 10-20 points) in order to avoid <a
  351.      * href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's phenomenon</a>
  352.      * and numerical problems (including NaN appearing).
  353.      * </p>
  354.      * @param date interpolation date
  355.      * @param cFilter filter for derivatives from the sample to use in interpolation
  356.      * @param aFilter filter for derivatives from the sample to use in interpolation
  357.      * @param sample sample points on which interpolation should be done
  358.      * @return a new instance, interpolated at specified date
  359.           * @since 7.0
  360.      */
  361.     public static Transform interpolate(final AbsoluteDate date,
  362.                                         final CartesianDerivativesFilter cFilter,
  363.                                         final AngularDerivativesFilter aFilter,
  364.                                         final Collection<Transform> sample) {
  365.         final List<TimeStampedPVCoordinates>      datedPV = new ArrayList<>(sample.size());
  366.         final List<TimeStampedAngularCoordinates> datedAC = new ArrayList<>(sample.size());
  367.         for (final Transform t : sample) {
  368.             datedPV.add(new TimeStampedPVCoordinates(t.getDate(), t.getTranslation(), t.getVelocity(), t.getAcceleration()));
  369.             datedAC.add(new TimeStampedAngularCoordinates(t.getDate(), t.getRotation(), t.getRotationRate(), t.getRotationAcceleration()));
  370.         }
  371.         final TimeStampedPVCoordinates      interpolatedPV = TimeStampedPVCoordinates.interpolate(date, cFilter, datedPV);
  372.         final TimeStampedAngularCoordinates interpolatedAC = TimeStampedAngularCoordinates.interpolate(date, aFilter, datedAC);
  373.         return new Transform(date, interpolatedPV, interpolatedAC);
  374.     }

  375.     /** Get the inverse transform of the instance.
  376.      * @return inverse transform of the instance
  377.      */
  378.     @Override
  379.     public Transform getInverse() {

  380.         final Rotation r    = angular.getRotation();
  381.         final Vector3D o    = angular.getRotationRate();
  382.         final Vector3D oDot = angular.getRotationAcceleration();
  383.         final Vector3D rp   = r.applyTo(cartesian.getPosition());
  384.         final Vector3D rv   = r.applyTo(cartesian.getVelocity());
  385.         final Vector3D ra   = r.applyTo(cartesian.getAcceleration());

  386.         final Vector3D pInv        = rp.negate();
  387.         final Vector3D crossP      = Vector3D.crossProduct(o, rp);
  388.         final Vector3D vInv        = crossP.subtract(rv);
  389.         final Vector3D crossV      = Vector3D.crossProduct(o, rv);
  390.         final Vector3D crossDotP   = Vector3D.crossProduct(oDot, rp);
  391.         final Vector3D crossCrossP = Vector3D.crossProduct(o, crossP);
  392.         final Vector3D aInv        = new Vector3D(-1, ra,
  393.                                                    2, crossV,
  394.                                                    1, crossDotP,
  395.                                                   -1, crossCrossP);

  396.         return new Transform(getDate(), new PVCoordinates(pInv, vInv, aInv), angular.revert());

  397.     }

  398.     /** Get a frozen transform.
  399.      * <p>
  400.      * This method creates a copy of the instance but frozen in time,
  401.      * i.e. with velocity, acceleration and rotation rate forced to zero.
  402.      * </p>
  403.      * @return a new transform, without any time-dependent parts
  404.      */
  405.     public Transform freeze() {
  406.         return new Transform(date,
  407.                              new PVCoordinates(cartesian.getPosition(), Vector3D.ZERO, Vector3D.ZERO),
  408.                              new AngularCoordinates(angular.getRotation(), Vector3D.ZERO, Vector3D.ZERO));
  409.     }

  410.     /** Transform {@link PVCoordinates} including kinematic effects.
  411.      * @param pva the position-velocity-acceleration triplet to transform.
  412.      * @return transformed position-velocity-acceleration
  413.      */
  414.     public PVCoordinates transformPVCoordinates(final PVCoordinates pva) {
  415.         return angular.applyTo(new PVCoordinates(1, pva, 1, cartesian));
  416.     }

  417.     /** Transform {@link TimeStampedPVCoordinates} including kinematic effects.
  418.      * <p>
  419.      * In order to allow the user more flexibility, this method does <em>not</em> check for
  420.      * consistency between the transform {@link #getDate() date} and the time-stamped
  421.      * position-velocity {@link TimeStampedPVCoordinates#getDate() date}. The returned
  422.      * value will always have the same {@link TimeStampedPVCoordinates#getDate() date} as
  423.      * the input argument, regardless of the instance {@link #getDate() date}.
  424.      * </p>
  425.      * @param pv time-stamped  position-velocity to transform.
  426.      * @return transformed time-stamped position-velocity
  427.      * @since 7.0
  428.      */
  429.     public TimeStampedPVCoordinates transformPVCoordinates(final TimeStampedPVCoordinates pv) {
  430.         return angular.applyTo(new TimeStampedPVCoordinates(pv.getDate(), 1, pv, 1, cartesian));
  431.     }

  432.     /** Transform {@link FieldPVCoordinates} including kinematic effects.
  433.      * @param pv position-velocity to transform.
  434.      * @param <T> type of the field elements
  435.      * @return transformed position-velocity
  436.      */
  437.     public <T extends CalculusFieldElement<T>> FieldPVCoordinates<T> transformPVCoordinates(final FieldPVCoordinates<T> pv) {
  438.         return angular.applyTo(new FieldPVCoordinates<>(pv.getPosition().add(cartesian.getPosition()),
  439.                                                         pv.getVelocity().add(cartesian.getVelocity()),
  440.                                                         pv.getAcceleration().add(cartesian.getAcceleration())));
  441.     }

  442.     /** Transform {@link TimeStampedFieldPVCoordinates} including kinematic effects.
  443.      * <p>
  444.      * In order to allow the user more flexibility, this method does <em>not</em> check for
  445.      * consistency between the transform {@link #getDate() date} and the time-stamped
  446.      * position-velocity {@link TimeStampedFieldPVCoordinates#getDate() date}. The returned
  447.      * value will always have the same {@link TimeStampedFieldPVCoordinates#getDate() date} as
  448.      * the input argument, regardless of the instance {@link #getDate() date}.
  449.      * </p>
  450.      * @param pv time-stamped position-velocity to transform.
  451.      * @param <T> type of the field elements
  452.      * @return transformed time-stamped position-velocity
  453.      * @since 7.0
  454.      */
  455.     public <T extends CalculusFieldElement<T>> TimeStampedFieldPVCoordinates<T> transformPVCoordinates(final TimeStampedFieldPVCoordinates<T> pv) {
  456.         return angular.applyTo(new TimeStampedFieldPVCoordinates<>(pv.getDate(),
  457.                                                                    pv.getPosition().add(cartesian.getPosition()),
  458.                                                                    pv.getVelocity().add(cartesian.getVelocity()),
  459.                                                                    pv.getAcceleration().add(cartesian.getAcceleration())));
  460.     }

  461.     /** Compute the Jacobian of the {@link #transformPVCoordinates(PVCoordinates)}
  462.      * method of the transform.
  463.      * <p>
  464.      * Element {@code jacobian[i][j]} is the derivative of Cartesian coordinate i
  465.      * of the transformed {@link PVCoordinates} with respect to Cartesian coordinate j
  466.      * of the input {@link PVCoordinates} in method {@link #transformPVCoordinates(PVCoordinates)}.
  467.      * </p>
  468.      * <p>
  469.      * This definition implies that if we define position-velocity coordinates
  470.      * <pre>
  471.      * PV₁ = transform.transformPVCoordinates(PV₀), then
  472.      * </pre>
  473.      * <p> their differentials dPV₁ and dPV₀ will obey the following relation
  474.      * where J is the matrix computed by this method:
  475.      * <pre>
  476.      * dPV₁ = J &times; dPV₀
  477.      * </pre>
  478.      *
  479.      * @param selector selector specifying the size of the upper left corner that must be filled
  480.      * (either 3x3 for positions only, 6x6 for positions and velocities, 9x9 for positions,
  481.      * velocities and accelerations)
  482.      * @param jacobian placeholder matrix whose upper-left corner is to be filled with
  483.      * the Jacobian, the rest of the matrix remaining untouched
  484.      */
  485.     public void getJacobian(final CartesianDerivativesFilter selector, final double[][] jacobian) {

  486.         // elementary matrix for rotation
  487.         final double[][] mData = angular.getRotation().getMatrix();

  488.         // dP1/dP0
  489.         System.arraycopy(mData[0], 0, jacobian[0], 0, 3);
  490.         System.arraycopy(mData[1], 0, jacobian[1], 0, 3);
  491.         System.arraycopy(mData[2], 0, jacobian[2], 0, 3);

  492.         if (selector.getMaxOrder() >= 1) {

  493.             // dP1/dV0
  494.             Arrays.fill(jacobian[0], 3, 6, 0.0);
  495.             Arrays.fill(jacobian[1], 3, 6, 0.0);
  496.             Arrays.fill(jacobian[2], 3, 6, 0.0);

  497.             // dV1/dP0
  498.             final Vector3D o = angular.getRotationRate();
  499.             final double ox = o.getX();
  500.             final double oy = o.getY();
  501.             final double oz = o.getZ();
  502.             for (int i = 0; i < 3; ++i) {
  503.                 jacobian[3][i] = -(oy * mData[2][i] - oz * mData[1][i]);
  504.                 jacobian[4][i] = -(oz * mData[0][i] - ox * mData[2][i]);
  505.                 jacobian[5][i] = -(ox * mData[1][i] - oy * mData[0][i]);
  506.             }

  507.             // dV1/dV0
  508.             System.arraycopy(mData[0], 0, jacobian[3], 3, 3);
  509.             System.arraycopy(mData[1], 0, jacobian[4], 3, 3);
  510.             System.arraycopy(mData[2], 0, jacobian[5], 3, 3);

  511.             if (selector.getMaxOrder() >= 2) {

  512.                 // dP1/dA0
  513.                 Arrays.fill(jacobian[0], 6, 9, 0.0);
  514.                 Arrays.fill(jacobian[1], 6, 9, 0.0);
  515.                 Arrays.fill(jacobian[2], 6, 9, 0.0);

  516.                 // dV1/dA0
  517.                 Arrays.fill(jacobian[3], 6, 9, 0.0);
  518.                 Arrays.fill(jacobian[4], 6, 9, 0.0);
  519.                 Arrays.fill(jacobian[5], 6, 9, 0.0);

  520.                 // dA1/dP0
  521.                 final Vector3D oDot = angular.getRotationAcceleration();
  522.                 final double oDotx  = oDot.getX();
  523.                 final double oDoty  = oDot.getY();
  524.                 final double oDotz  = oDot.getZ();
  525.                 for (int i = 0; i < 3; ++i) {
  526.                     jacobian[6][i] = -(oDoty * mData[2][i] - oDotz * mData[1][i]) - (oy * jacobian[5][i] - oz * jacobian[4][i]);
  527.                     jacobian[7][i] = -(oDotz * mData[0][i] - oDotx * mData[2][i]) - (oz * jacobian[3][i] - ox * jacobian[5][i]);
  528.                     jacobian[8][i] = -(oDotx * mData[1][i] - oDoty * mData[0][i]) - (ox * jacobian[4][i] - oy * jacobian[3][i]);
  529.                 }

  530.                 // dA1/dV0
  531.                 for (int i = 0; i < 3; ++i) {
  532.                     jacobian[6][i + 3] = -2 * (oy * mData[2][i] - oz * mData[1][i]);
  533.                     jacobian[7][i + 3] = -2 * (oz * mData[0][i] - ox * mData[2][i]);
  534.                     jacobian[8][i + 3] = -2 * (ox * mData[1][i] - oy * mData[0][i]);
  535.                 }

  536.                 // dA1/dA0
  537.                 System.arraycopy(mData[0], 0, jacobian[6], 6, 3);
  538.                 System.arraycopy(mData[1], 0, jacobian[7], 6, 3);
  539.                 System.arraycopy(mData[2], 0, jacobian[8], 6, 3);

  540.             }

  541.         }

  542.     }

  543.     /** Get the underlying elementary Cartesian part.
  544.      * <p>A transform can be uniquely represented as an elementary
  545.      * translation followed by an elementary rotation. This method
  546.      * returns this unique elementary translation with its derivative.</p>
  547.      * @return underlying elementary Cartesian part
  548.      * @see #getTranslation()
  549.      * @see #getVelocity()
  550.      */
  551.     public PVCoordinates getCartesian() {
  552.         return cartesian;
  553.     }

  554.     /** Get the underlying elementary translation.
  555.      * <p>A transform can be uniquely represented as an elementary
  556.      * translation followed by an elementary rotation. This method
  557.      * returns this unique elementary translation.</p>
  558.      * @return underlying elementary translation
  559.      * @see #getCartesian()
  560.      * @see #getVelocity()
  561.      * @see #getAcceleration()
  562.      */
  563.     public Vector3D getTranslation() {
  564.         return cartesian.getPosition();
  565.     }

  566.     /** Get the first time derivative of the translation.
  567.      * @return first time derivative of the translation
  568.      * @see #getCartesian()
  569.      * @see #getTranslation()
  570.      * @see #getAcceleration()
  571.      */
  572.     public Vector3D getVelocity() {
  573.         return cartesian.getVelocity();
  574.     }

  575.     /** Get the second time derivative of the translation.
  576.      * @return second time derivative of the translation
  577.      * @see #getCartesian()
  578.      * @see #getTranslation()
  579.      * @see #getVelocity()
  580.      */
  581.     public Vector3D getAcceleration() {
  582.         return cartesian.getAcceleration();
  583.     }

  584.     /** Get the underlying elementary angular part.
  585.      * <p>A transform can be uniquely represented as an elementary
  586.      * translation followed by an elementary rotation. This method
  587.      * returns this unique elementary rotation with its derivative.</p>
  588.      * @return underlying elementary angular part
  589.      * @see #getRotation()
  590.      * @see #getRotationRate()
  591.      * @see #getRotationAcceleration()
  592.      */
  593.     public AngularCoordinates getAngular() {
  594.         return angular;
  595.     }

  596.     /** Get the underlying elementary rotation.
  597.      * <p>A transform can be uniquely represented as an elementary
  598.      * translation followed by an elementary rotation. This method
  599.      * returns this unique elementary rotation.</p>
  600.      * @return underlying elementary rotation
  601.      * @see #getAngular()
  602.      * @see #getRotationRate()
  603.      * @see #getRotationAcceleration()
  604.      */
  605.     public Rotation getRotation() {
  606.         return angular.getRotation();
  607.     }

  608.     /** Get the first time derivative of the rotation.
  609.      * <p>The norm represents the angular rate.</p>
  610.      * @return First time derivative of the rotation
  611.      * @see #getAngular()
  612.      * @see #getRotation()
  613.      * @see #getRotationAcceleration()
  614.      */
  615.     public Vector3D getRotationRate() {
  616.         return angular.getRotationRate();
  617.     }

  618.     /** Get the second time derivative of the rotation.
  619.      * @return Second time derivative of the rotation
  620.      * @see #getAngular()
  621.      * @see #getRotation()
  622.      * @see #getRotationRate()
  623.      */
  624.     public Vector3D getRotationAcceleration() {
  625.         return angular.getRotationAcceleration();
  626.     }

  627.     /** Specialized class for identity transform. */
  628.     private static class IdentityTransform extends Transform {

  629.         /** Serializable UID. */
  630.         private static final long serialVersionUID = -9042082036141830517L;

  631.         /** Simple constructor. */
  632.         IdentityTransform() {
  633.             super(AbsoluteDate.ARBITRARY_EPOCH, PVCoordinates.ZERO, AngularCoordinates.IDENTITY);
  634.         }

  635.         /** {@inheritDoc} */
  636.         @Override
  637.         public Transform shiftedBy(final double dt) {
  638.             return this;
  639.         }

  640.         /** {@inheritDoc} */
  641.         @Override
  642.         public Transform getInverse() {
  643.             return this;
  644.         }

  645.         /** {@inheritDoc} */
  646.         @Override
  647.         public Vector3D transformPosition(final Vector3D position) {
  648.             return position;
  649.         }

  650.         /** {@inheritDoc} */
  651.         @Override
  652.         public Vector3D transformVector(final Vector3D vector) {
  653.             return vector;
  654.         }

  655.         /** {@inheritDoc} */
  656.         @Override
  657.         public Line transformLine(final Line line) {
  658.             return line;
  659.         }

  660.         /** {@inheritDoc} */
  661.         @Override
  662.         public PVCoordinates transformPVCoordinates(final PVCoordinates pv) {
  663.             return pv;
  664.         }

  665.         @Override
  666.         public Transform freeze() {
  667.             return this;
  668.         }

  669.         @Override
  670.         public TimeStampedPVCoordinates transformPVCoordinates(
  671.                 final TimeStampedPVCoordinates pv) {
  672.             return pv;
  673.         }

  674.         @Override
  675.         public <T extends CalculusFieldElement<T>> FieldPVCoordinates<T>
  676.             transformPVCoordinates(final FieldPVCoordinates<T> pv) {
  677.             return pv;
  678.         }

  679.         @Override
  680.         public <T extends CalculusFieldElement<T>>
  681.             TimeStampedFieldPVCoordinates<T> transformPVCoordinates(
  682.                     final TimeStampedFieldPVCoordinates<T> pv) {
  683.             return pv;
  684.         }

  685.         /** {@inheritDoc} */
  686.         @Override
  687.         public void getJacobian(final CartesianDerivativesFilter selector, final double[][] jacobian) {
  688.             final int n = 3 * (selector.getMaxOrder() + 1);
  689.             for (int i = 0; i < n; ++i) {
  690.                 Arrays.fill(jacobian[i], 0, n, 0.0);
  691.                 jacobian[i][i] = 1.0;
  692.             }
  693.         }

  694.     }

  695. }