Transform.java

  1. /* Copyright 2002-2019 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.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.RealFieldElement;
  26. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  27. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  28. import org.hipparchus.geometry.euclidean.threed.Line;
  29. import org.hipparchus.geometry.euclidean.threed.Rotation;
  30. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  31. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  32. import org.orekit.time.AbsoluteDate;
  33. import org.orekit.time.TimeInterpolable;
  34. import org.orekit.time.TimeShiftable;
  35. import org.orekit.time.TimeStamped;
  36. import org.orekit.utils.AngularCoordinates;
  37. import org.orekit.utils.AngularDerivativesFilter;
  38. import org.orekit.utils.CartesianDerivativesFilter;
  39. import org.orekit.utils.FieldPVCoordinates;
  40. import org.orekit.utils.PVCoordinates;
  41. import org.orekit.utils.TimeStampedAngularCoordinates;
  42. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  43. import org.orekit.utils.TimeStampedPVCoordinates;


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  248.         final Vector3D p1 = first.cartesian.getPosition();
  249.         final Rotation r1 = first.angular.getRotation();
  250.         final Vector3D p2 = second.cartesian.getPosition();

  251.         return p1.add(r1.applyInverseTo(p2));

  252.     }

  253.     /** Compute a composite velocity.
  254.      * @param first first applied transform
  255.      * @param second second applied transform
  256.      * @return velocity part of the composite transform
  257.      */
  258.     private static Vector3D compositeVelocity(final Transform first, final Transform second) {

  259.         final Vector3D v1 = first.cartesian.getVelocity();
  260.         final Rotation r1 = first.angular.getRotation();
  261.         final Vector3D o1 = first.angular.getRotationRate();
  262.         final Vector3D p2 = second.cartesian.getPosition();
  263.         final Vector3D v2 = second.cartesian.getVelocity();

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

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

  266.     }

  267.     /** Compute a composite acceleration.
  268.      * @param first first applied transform
  269.      * @param second second applied transform
  270.      * @return acceleration part of the composite transform
  271.      */
  272.     private static Vector3D compositeAcceleration(final Transform first, final Transform second) {

  273.         final Vector3D a1    = first.cartesian.getAcceleration();
  274.         final Rotation r1    = first.angular.getRotation();
  275.         final Vector3D o1    = first.angular.getRotationRate();
  276.         final Vector3D oDot1 = first.angular.getRotationAcceleration();
  277.         final Vector3D p2    = second.cartesian.getPosition();
  278.         final Vector3D v2    = second.cartesian.getVelocity();
  279.         final Vector3D a2    = second.cartesian.getAcceleration();

  280.         final Vector3D crossCrossP = Vector3D.crossProduct(o1,    Vector3D.crossProduct(o1, p2));
  281.         final Vector3D crossV      = Vector3D.crossProduct(o1,    v2);
  282.         final Vector3D crossDotP   = Vector3D.crossProduct(oDot1, p2);

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

  284.     }

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

  291.         final Rotation r1 = first.angular.getRotation();
  292.         final Rotation r2 = second.angular.getRotation();

  293.         return r1.compose(r2, RotationConvention.FRAME_TRANSFORM);

  294.     }

  295.     /** Compute a composite rotation rate.
  296.      * @param first first applied transform
  297.      * @param second second applied transform
  298.      * @return rotation rate part of the composite transform
  299.      */
  300.     private static Vector3D compositeRotationRate(final Transform first, final Transform second) {

  301.         final Vector3D o1 = first.angular.getRotationRate();
  302.         final Rotation r2 = second.angular.getRotation();
  303.         final Vector3D o2 = second.angular.getRotationRate();

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

  305.     }

  306.     /** Compute a composite rotation acceleration.
  307.      * @param first first applied transform
  308.      * @param second second applied transform
  309.      * @return rotation acceleration part of the composite transform
  310.      */
  311.     private static Vector3D compositeRotationAcceleration(final Transform first, final Transform second) {

  312.         final Vector3D o1    = first.angular.getRotationRate();
  313.         final Vector3D oDot1 = first.angular.getRotationAcceleration();
  314.         final Rotation r2    = second.angular.getRotation();
  315.         final Vector3D o2    = second.angular.getRotationRate();
  316.         final Vector3D oDot2 = second.angular.getRotationAcceleration();

  317.         return new Vector3D( 1, oDot2,
  318.                              1, r2.applyTo(oDot1),
  319.                             -1, Vector3D.crossProduct(o2, r2.applyTo(o1)));

  320.     }

  321.     /** {@inheritDoc} */
  322.     public AbsoluteDate getDate() {
  323.         return date;
  324.     }

  325.     /** {@inheritDoc} */
  326.     public Transform shiftedBy(final double dt) {
  327.         return new Transform(date.shiftedBy(dt), cartesian.shiftedBy(dt), angular.shiftedBy(dt));
  328.     }

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

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

  381.     /** Get the inverse transform of the instance.
  382.      * @return inverse transform of the instance
  383.      */
  384.     public Transform getInverse() {

  385.         final Rotation r    = angular.getRotation();
  386.         final Vector3D o    = angular.getRotationRate();
  387.         final Vector3D oDot = angular.getRotationAcceleration();
  388.         final Vector3D rp   = r.applyTo(cartesian.getPosition());
  389.         final Vector3D rv   = r.applyTo(cartesian.getVelocity());
  390.         final Vector3D ra   = r.applyTo(cartesian.getAcceleration());

  391.         final Vector3D pInv        = rp.negate();
  392.         final Vector3D crossP      = Vector3D.crossProduct(o, rp);
  393.         final Vector3D vInv        = crossP.subtract(rv);
  394.         final Vector3D crossV      = Vector3D.crossProduct(o, rv);
  395.         final Vector3D crossDotP   = Vector3D.crossProduct(oDot, rp);
  396.         final Vector3D crossCrossP = Vector3D.crossProduct(o, crossP);
  397.         final Vector3D aInv        = new Vector3D(-1, ra,
  398.                                                    2, crossV,
  399.                                                    1, crossDotP,
  400.                                                   -1, crossCrossP);

  401.         return new Transform(date, new PVCoordinates(pInv, vInv, aInv), angular.revert());

  402.     }

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

  415.     /** Transform a position vector (including translation effects).
  416.      * @param position vector to transform
  417.      * @return transformed position
  418.      */
  419.     public Vector3D transformPosition(final Vector3D position) {
  420.         return angular.getRotation().applyTo(cartesian.getPosition().add(position));
  421.     }

  422.     /** Transform a position vector (including translation effects).
  423.      * @param position vector to transform
  424.      * @param <T> the type of the field elements
  425.      * @return transformed position
  426.      */
  427.     public <T extends RealFieldElement<T>> FieldVector3D<T> transformPosition(final FieldVector3D<T> position) {
  428.         return FieldRotation.applyTo(angular.getRotation(), position.add(cartesian.getPosition()));
  429.     }

  430.     /** Transform a vector (ignoring translation effects).
  431.      * @param vector vector to transform
  432.      * @return transformed vector
  433.      */
  434.     public Vector3D transformVector(final Vector3D vector) {
  435.         return angular.getRotation().applyTo(vector);
  436.     }

  437.     /** Transform a vector (ignoring translation effects).
  438.      * @param vector vector to transform
  439.      * @param <T> the type of the field elements
  440.      * @return transformed vector
  441.      */
  442.     public <T extends RealFieldElement<T>> FieldVector3D<T> transformVector(final FieldVector3D<T> vector) {
  443.         return FieldRotation.applyTo(angular.getRotation(), vector);
  444.     }

  445.     /** Transform a line.
  446.      * @param line to transform
  447.      * @return transformed line
  448.      */
  449.     public Line transformLine(final Line line) {
  450.         final Vector3D transformedP0 = transformPosition(line.getOrigin());
  451.         final Vector3D transformedP1 = transformPosition(line.pointAt(1.0e6));
  452.         return new Line(transformedP0, transformedP1, 1.0e-10);
  453.     }

  454.     /** Transform {@link PVCoordinates} including kinematic effects.
  455.      * @param pva the position-velocity-acceleration triplet to transform.
  456.      * @return transformed position-velocity-acceleration
  457.      */
  458.     public PVCoordinates transformPVCoordinates(final PVCoordinates pva) {
  459.         return angular.applyTo(new PVCoordinates(1, pva, 1, cartesian));
  460.     }

  461.     /** Transform {@link TimeStampedPVCoordinates} including kinematic effects.
  462.      * <p>
  463.      * In order to allow the user more flexibility, this method does <em>not</em> check for
  464.      * consistency between the transform {@link #getDate() date} and the time-stamped
  465.      * position-velocity {@link TimeStampedPVCoordinates#getDate() date}. The returned
  466.      * value will always have the same {@link TimeStampedPVCoordinates#getDate() date} as
  467.      * the input argument, regardless of the instance {@link #getDate() date}.
  468.      * </p>
  469.      * @param pv time-stamped  position-velocity to transform.
  470.      * @return transformed time-stamped position-velocity
  471.      * @since 7.0
  472.      */
  473.     public TimeStampedPVCoordinates transformPVCoordinates(final TimeStampedPVCoordinates pv) {
  474.         return angular.applyTo(new TimeStampedPVCoordinates(pv.getDate(), 1, pv, 1, cartesian));
  475.     }

  476.     /** Transform {@link FieldPVCoordinates} including kinematic effects.
  477.      * @param pv position-velocity to transform.
  478.      * @param <T> type of the field elements
  479.      * @return transformed position-velocity
  480.      */
  481.     public <T extends RealFieldElement<T>> FieldPVCoordinates<T> transformPVCoordinates(final FieldPVCoordinates<T> pv) {
  482.         return angular.applyTo(new FieldPVCoordinates<>(pv.getPosition().add(cartesian.getPosition()),
  483.                                                         pv.getVelocity().add(cartesian.getVelocity()),
  484.                                                         pv.getAcceleration().add(cartesian.getAcceleration())));
  485.     }

  486.     /** Transform {@link TimeStampedFieldPVCoordinates} including kinematic effects.
  487.      * <p>
  488.      * In order to allow the user more flexibility, this method does <em>not</em> check for
  489.      * consistency between the transform {@link #getDate() date} and the time-stamped
  490.      * position-velocity {@link TimeStampedFieldPVCoordinates#getDate() date}. The returned
  491.      * value will always have the same {@link TimeStampedFieldPVCoordinates#getDate() date} as
  492.      * the input argument, regardless of the instance {@link #getDate() date}.
  493.      * </p>
  494.      * @param pv time-stamped position-velocity to transform.
  495.      * @param <T> type of the field elements
  496.      * @return transformed time-stamped position-velocity
  497.      * @since 7.0
  498.      */
  499.     public <T extends RealFieldElement<T>> TimeStampedFieldPVCoordinates<T> transformPVCoordinates(final TimeStampedFieldPVCoordinates<T> pv) {
  500.         return angular.applyTo(new TimeStampedFieldPVCoordinates<>(pv.getDate(),
  501.                                                                    pv.getPosition().add(cartesian.getPosition()),
  502.                                                                    pv.getVelocity().add(cartesian.getVelocity()),
  503.                                                                    pv.getAcceleration().add(cartesian.getAcceleration())));
  504.     }

  505.     /** Compute the Jacobian of the {@link #transformPVCoordinates(PVCoordinates)}
  506.      * method of the transform.
  507.      * <p>
  508.      * Element {@code jacobian[i][j]} is the derivative of Cartesian coordinate i
  509.      * of the transformed {@link PVCoordinates} with respect to Cartesian coordinate j
  510.      * of the input {@link PVCoordinates} in method {@link #transformPVCoordinates(PVCoordinates)}.
  511.      * </p>
  512.      * <p>
  513.      * This definition implies that if we define position-velocity coordinates
  514.      * <pre>
  515.      * PV₁ = transform.transformPVCoordinates(PV₀), then
  516.      * </pre>
  517.      * <p> their differentials dPV₁ and dPV₀ will obey the following relation
  518.      * where J is the matrix computed by this method:
  519.      * <pre>
  520.      * dPV₁ = J &times; dPV₀
  521.      * </pre>
  522.      *
  523.      * @param selector selector specifying the size of the upper left corner that must be filled
  524.      * (either 3x3 for positions only, 6x6 for positions and velocities, 9x9 for positions,
  525.      * velocities and accelerations)
  526.      * @param jacobian placeholder matrix whose upper-left corner is to be filled with
  527.      * the Jacobian, the rest of the matrix remaining untouched
  528.      */
  529.     public void getJacobian(final CartesianDerivativesFilter selector, final double[][] jacobian) {

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

  532.         // dP1/dP0
  533.         System.arraycopy(mData[0], 0, jacobian[0], 0, 3);
  534.         System.arraycopy(mData[1], 0, jacobian[1], 0, 3);
  535.         System.arraycopy(mData[2], 0, jacobian[2], 0, 3);

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

  537.             // dP1/dV0
  538.             Arrays.fill(jacobian[0], 3, 6, 0.0);
  539.             Arrays.fill(jacobian[1], 3, 6, 0.0);
  540.             Arrays.fill(jacobian[2], 3, 6, 0.0);

  541.             // dV1/dP0
  542.             final Vector3D o = angular.getRotationRate();
  543.             final double ox = o.getX();
  544.             final double oy = o.getY();
  545.             final double oz = o.getZ();
  546.             for (int i = 0; i < 3; ++i) {
  547.                 jacobian[3][i] = -(oy * mData[2][i] - oz * mData[1][i]);
  548.                 jacobian[4][i] = -(oz * mData[0][i] - ox * mData[2][i]);
  549.                 jacobian[5][i] = -(ox * mData[1][i] - oy * mData[0][i]);
  550.             }

  551.             // dV1/dV0
  552.             System.arraycopy(mData[0], 0, jacobian[3], 3, 3);
  553.             System.arraycopy(mData[1], 0, jacobian[4], 3, 3);
  554.             System.arraycopy(mData[2], 0, jacobian[5], 3, 3);

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

  556.                 // dP1/dA0
  557.                 Arrays.fill(jacobian[0], 6, 9, 0.0);
  558.                 Arrays.fill(jacobian[1], 6, 9, 0.0);
  559.                 Arrays.fill(jacobian[2], 6, 9, 0.0);

  560.                 // dV1/dA0
  561.                 Arrays.fill(jacobian[3], 6, 9, 0.0);
  562.                 Arrays.fill(jacobian[4], 6, 9, 0.0);
  563.                 Arrays.fill(jacobian[5], 6, 9, 0.0);

  564.                 // dA1/dP0
  565.                 final Vector3D oDot = angular.getRotationAcceleration();
  566.                 final double oDotx  = oDot.getX();
  567.                 final double oDoty  = oDot.getY();
  568.                 final double oDotz  = oDot.getZ();
  569.                 for (int i = 0; i < 3; ++i) {
  570.                     jacobian[6][i] = -(oDoty * mData[2][i] - oDotz * mData[1][i]) - (oy * jacobian[5][i] - oz * jacobian[4][i]);
  571.                     jacobian[7][i] = -(oDotz * mData[0][i] - oDotx * mData[2][i]) - (oz * jacobian[3][i] - ox * jacobian[5][i]);
  572.                     jacobian[8][i] = -(oDotx * mData[1][i] - oDoty * mData[0][i]) - (ox * jacobian[4][i] - oy * jacobian[3][i]);
  573.                 }

  574.                 // dA1/dV0
  575.                 for (int i = 0; i < 3; ++i) {
  576.                     jacobian[6][i + 3] = -2 * (oy * mData[2][i] - oz * mData[1][i]);
  577.                     jacobian[7][i + 3] = -2 * (oz * mData[0][i] - ox * mData[2][i]);
  578.                     jacobian[8][i + 3] = -2 * (ox * mData[1][i] - oy * mData[0][i]);
  579.                 }

  580.                 // dA1/dA0
  581.                 System.arraycopy(mData[0], 0, jacobian[6], 6, 3);
  582.                 System.arraycopy(mData[1], 0, jacobian[7], 6, 3);
  583.                 System.arraycopy(mData[2], 0, jacobian[8], 6, 3);

  584.             }

  585.         }

  586.     }

  587.     /** Get the underlying elementary Cartesian part.
  588.      * <p>A transform can be uniquely represented as an elementary
  589.      * translation followed by an elementary rotation. This method
  590.      * returns this unique elementary translation with its derivative.</p>
  591.      * @return underlying elementary Cartesian part
  592.      * @see #getTranslation()
  593.      * @see #getVelocity()
  594.      */
  595.     public PVCoordinates getCartesian() {
  596.         return cartesian;
  597.     }

  598.     /** Get the underlying elementary translation.
  599.      * <p>A transform can be uniquely represented as an elementary
  600.      * translation followed by an elementary rotation. This method
  601.      * returns this unique elementary translation.</p>
  602.      * @return underlying elementary translation
  603.      * @see #getCartesian()
  604.      * @see #getVelocity()
  605.      * @see #getAcceleration()
  606.      */
  607.     public Vector3D getTranslation() {
  608.         return cartesian.getPosition();
  609.     }

  610.     /** Get the first time derivative of the translation.
  611.      * @return first time derivative of the translation
  612.      * @see #getCartesian()
  613.      * @see #getTranslation()
  614.      * @see #getAcceleration()
  615.      */
  616.     public Vector3D getVelocity() {
  617.         return cartesian.getVelocity();
  618.     }

  619.     /** Get the second time derivative of the translation.
  620.      * @return second time derivative of the translation
  621.      * @see #getCartesian()
  622.      * @see #getTranslation()
  623.      * @see #getVelocity()
  624.      */
  625.     public Vector3D getAcceleration() {
  626.         return cartesian.getAcceleration();
  627.     }

  628.     /** Get the underlying elementary angular part.
  629.      * <p>A transform can be uniquely represented as an elementary
  630.      * translation followed by an elementary rotation. This method
  631.      * returns this unique elementary rotation with its derivative.</p>
  632.      * @return underlying elementary angular part
  633.      * @see #getRotation()
  634.      * @see #getRotationRate()
  635.      * @see #getRotationAcceleration()
  636.      */
  637.     public AngularCoordinates getAngular() {
  638.         return angular;
  639.     }

  640.     /** Get the underlying elementary rotation.
  641.      * <p>A transform can be uniquely represented as an elementary
  642.      * translation followed by an elementary rotation. This method
  643.      * returns this unique elementary rotation.</p>
  644.      * @return underlying elementary rotation
  645.      * @see #getAngular()
  646.      * @see #getRotationRate()
  647.      * @see #getRotationAcceleration()
  648.      */
  649.     public Rotation getRotation() {
  650.         return angular.getRotation();
  651.     }

  652.     /** Get the first time derivative of the rotation.
  653.      * <p>The norm represents the angular rate.</p>
  654.      * @return First time derivative of the rotation
  655.      * @see #getAngular()
  656.      * @see #getRotation()
  657.      * @see #getRotationAcceleration()
  658.      */
  659.     public Vector3D getRotationRate() {
  660.         return angular.getRotationRate();
  661.     }

  662.     /** Get the second time derivative of the rotation.
  663.      * @return Second time derivative of the rotation
  664.      * @see #getAngular()
  665.      * @see #getRotation()
  666.      * @see #getRotationRate()
  667.      */
  668.     public Vector3D getRotationAcceleration() {
  669.         return angular.getRotationAcceleration();
  670.     }

  671.     /** Specialized class for identity transform. */
  672.     private static class IdentityTransform extends Transform {

  673.         /** Serializable UID. */
  674.         private static final long serialVersionUID = -9042082036141830517L;

  675.         /** Simple constructor. */
  676.         IdentityTransform() {
  677.             super(AbsoluteDate.J2000_EPOCH, PVCoordinates.ZERO, AngularCoordinates.IDENTITY);
  678.         }

  679.         /** {@inheritDoc} */
  680.         @Override
  681.         public Transform shiftedBy(final double dt) {
  682.             return this;
  683.         }

  684.         /** {@inheritDoc} */
  685.         @Override
  686.         public Transform getInverse() {
  687.             return this;
  688.         }

  689.         /** {@inheritDoc} */
  690.         @Override
  691.         public Vector3D transformPosition(final Vector3D position) {
  692.             return position;
  693.         }

  694.         /** {@inheritDoc} */
  695.         @Override
  696.         public Vector3D transformVector(final Vector3D vector) {
  697.             return vector;
  698.         }

  699.         /** {@inheritDoc} */
  700.         @Override
  701.         public Line transformLine(final Line line) {
  702.             return line;
  703.         }

  704.         /** {@inheritDoc} */
  705.         @Override
  706.         public PVCoordinates transformPVCoordinates(final PVCoordinates pv) {
  707.             return pv;
  708.         }

  709.         /** {@inheritDoc} */
  710.         @Override
  711.         public void getJacobian(final CartesianDerivativesFilter selector, final double[][] jacobian) {
  712.             final int n = 3 * (selector.getMaxOrder() + 1);
  713.             for (int i = 0; i < n; ++i) {
  714.                 Arrays.fill(jacobian[i], 0, n, 0.0);
  715.                 jacobian[i][i] = 1.0;
  716.             }
  717.         }

  718.     }

  719. }