PVCoordinates.java

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

  18. import java.io.Serializable;

  19. import org.hipparchus.analysis.differentiation.DSFactory;
  20. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.hipparchus.util.FastMath;
  24. import org.orekit.errors.OrekitException;
  25. import org.orekit.errors.OrekitMessages;
  26. import org.orekit.time.TimeShiftable;

  27. /** Simple container for Position/Velocity/Acceleration triplets.
  28.  * <p>
  29.  * The state can be slightly shifted to close dates. This shift is based on
  30.  * a simple quadratic model. It is <em>not</em> intended as a replacement for
  31.  * proper orbit propagation (it is not even Keplerian!) but should be sufficient
  32.  * for either small time shifts or coarse accuracy.
  33.  * </p>
  34.  * <p>
  35.  * This class is the angular counterpart to {@link AngularCoordinates}.
  36.  * </p>
  37.  * <p>Instances of this class are guaranteed to be immutable.</p>
  38.  * @author Fabien Maussion
  39.  * @author Luc Maisonobe
  40.  */
  41. public class PVCoordinates implements TimeShiftable<PVCoordinates>, Serializable {

  42.     /** Fixed position/velocity at origin (both p, v and a are zero vectors). */
  43.     public static final PVCoordinates ZERO = new PVCoordinates(Vector3D.ZERO, Vector3D.ZERO, Vector3D.ZERO);

  44.     /** Serializable UID. */
  45.     private static final long serialVersionUID = 20140407L;

  46.     /** The position. */
  47.     private final Vector3D position;

  48.     /** The velocity. */
  49.     private final Vector3D velocity;

  50.     /** The acceleration. */
  51.     private final Vector3D acceleration;

  52.     /** Simple constructor.
  53.      * <p> Set the Coordinates to default : (0 0 0), (0 0 0), (0 0 0).</p>
  54.      */
  55.     public PVCoordinates() {
  56.         position     = Vector3D.ZERO;
  57.         velocity     = Vector3D.ZERO;
  58.         acceleration = Vector3D.ZERO;
  59.     }

  60.     /** Builds a PVCoordinates triplet with zero acceleration.
  61.      * <p>Acceleration is set to zero</p>
  62.      * @param position the position vector (m)
  63.      * @param velocity the velocity vector (m/s)
  64.      */
  65.     public PVCoordinates(final Vector3D position, final Vector3D velocity) {
  66.         this.position     = position;
  67.         this.velocity     = velocity;
  68.         this.acceleration = Vector3D.ZERO;
  69.     }

  70.     /** Builds a PVCoordinates triplet.
  71.      * @param position the position vector (m)
  72.      * @param velocity the velocity vector (m/s)
  73.      * @param acceleration the acceleration vector (m/s²)
  74.      */
  75.     public PVCoordinates(final Vector3D position, final Vector3D velocity, final Vector3D acceleration) {
  76.         this.position     = position;
  77.         this.velocity     = velocity;
  78.         this.acceleration = acceleration;
  79.     }

  80.     /** Multiplicative constructor.
  81.      * <p>Build a PVCoordinates from another one and a scale factor.</p>
  82.      * <p>The PVCoordinates built will be a * pv</p>
  83.      * @param a scale factor
  84.      * @param pv base (unscaled) PVCoordinates
  85.      */
  86.     public PVCoordinates(final double a, final PVCoordinates pv) {
  87.         position     = new Vector3D(a, pv.position);
  88.         velocity     = new Vector3D(a, pv.velocity);
  89.         acceleration = new Vector3D(a, pv.acceleration);
  90.     }

  91.     /** Subtractive constructor.
  92.      * <p>Build a relative PVCoordinates from a start and an end position.</p>
  93.      * <p>The PVCoordinates built will be end - start.</p>
  94.      * @param start Starting PVCoordinates
  95.      * @param end ending PVCoordinates
  96.      */
  97.     public PVCoordinates(final PVCoordinates start, final PVCoordinates end) {
  98.         this.position     = end.position.subtract(start.position);
  99.         this.velocity     = end.velocity.subtract(start.velocity);
  100.         this.acceleration = end.acceleration.subtract(start.acceleration);
  101.     }

  102.     /** Linear constructor.
  103.      * <p>Build a PVCoordinates from two other ones and corresponding scale factors.</p>
  104.      * <p>The PVCoordinates built will be a1 * u1 + a2 * u2</p>
  105.      * @param a1 first scale factor
  106.      * @param pv1 first base (unscaled) PVCoordinates
  107.      * @param a2 second scale factor
  108.      * @param pv2 second base (unscaled) PVCoordinates
  109.      */
  110.     public PVCoordinates(final double a1, final PVCoordinates pv1,
  111.                          final double a2, final PVCoordinates pv2) {
  112.         position     = new Vector3D(a1, pv1.position,     a2, pv2.position);
  113.         velocity     = new Vector3D(a1, pv1.velocity,     a2, pv2.velocity);
  114.         acceleration = new Vector3D(a1, pv1.acceleration, a2, pv2.acceleration);
  115.     }

  116.     /** Linear constructor.
  117.      * <p>Build a PVCoordinates from three other ones and corresponding scale factors.</p>
  118.      * <p>The PVCoordinates built will be a1 * u1 + a2 * u2 + a3 * u3</p>
  119.      * @param a1 first scale factor
  120.      * @param pv1 first base (unscaled) PVCoordinates
  121.      * @param a2 second scale factor
  122.      * @param pv2 second base (unscaled) PVCoordinates
  123.      * @param a3 third scale factor
  124.      * @param pv3 third base (unscaled) PVCoordinates
  125.      */
  126.     public PVCoordinates(final double a1, final PVCoordinates pv1,
  127.                          final double a2, final PVCoordinates pv2,
  128.                          final double a3, final PVCoordinates pv3) {
  129.         position     = new Vector3D(a1, pv1.position,     a2, pv2.position,     a3, pv3.position);
  130.         velocity     = new Vector3D(a1, pv1.velocity,     a2, pv2.velocity,     a3, pv3.velocity);
  131.         acceleration = new Vector3D(a1, pv1.acceleration, a2, pv2.acceleration, a3, pv3.acceleration);
  132.     }

  133.     /** Linear constructor.
  134.      * <p>Build a PVCoordinates from four other ones and corresponding scale factors.</p>
  135.      * <p>The PVCoordinates built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4</p>
  136.      * @param a1 first scale factor
  137.      * @param pv1 first base (unscaled) PVCoordinates
  138.      * @param a2 second scale factor
  139.      * @param pv2 second base (unscaled) PVCoordinates
  140.      * @param a3 third scale factor
  141.      * @param pv3 third base (unscaled) PVCoordinates
  142.      * @param a4 fourth scale factor
  143.      * @param pv4 fourth base (unscaled) PVCoordinates
  144.      */
  145.     public PVCoordinates(final double a1, final PVCoordinates pv1,
  146.                          final double a2, final PVCoordinates pv2,
  147.                          final double a3, final PVCoordinates pv3,
  148.                          final double a4, final PVCoordinates pv4) {
  149.         position     = new Vector3D(a1, pv1.position,     a2, pv2.position,
  150.                                     a3, pv3.position,     a4, pv4.position);
  151.         velocity     = new Vector3D(a1, pv1.velocity,     a2, pv2.velocity,
  152.                                     a3, pv3.velocity,     a4, pv4.velocity);
  153.         acceleration = new Vector3D(a1, pv1.acceleration, a2, pv2.acceleration,
  154.                                     a3, pv3.acceleration, a4, pv4.acceleration);
  155.     }

  156.     /** Builds a PVCoordinates triplet from  a {@link FieldVector3D}&lt;{@link DerivativeStructure}&gt;.
  157.      * <p>
  158.      * The vector components must have time as their only derivation parameter and
  159.      * have consistent derivation orders.
  160.      * </p>
  161.      * @param p vector with time-derivatives embedded within the coordinates
  162.      */
  163.     public PVCoordinates(final FieldVector3D<DerivativeStructure> p) {
  164.         position = new Vector3D(p.getX().getReal(), p.getY().getReal(), p.getZ().getReal());
  165.         if (p.getX().getOrder() >= 1) {
  166.             velocity = new Vector3D(p.getX().getPartialDerivative(1),
  167.                                     p.getY().getPartialDerivative(1),
  168.                                     p.getZ().getPartialDerivative(1));
  169.             if (p.getX().getOrder() >= 2) {
  170.                 acceleration = new Vector3D(p.getX().getPartialDerivative(2),
  171.                                             p.getY().getPartialDerivative(2),
  172.                                             p.getZ().getPartialDerivative(2));
  173.             } else {
  174.                 acceleration = Vector3D.ZERO;
  175.             }
  176.         } else {
  177.             velocity     = Vector3D.ZERO;
  178.             acceleration = Vector3D.ZERO;
  179.         }
  180.     }

  181.     /** Transform the instance to a {@link FieldVector3D}&lt;{@link DerivativeStructure}&gt;.
  182.      * <p>
  183.      * The {@link DerivativeStructure} coordinates correspond to time-derivatives up
  184.      * to the user-specified order.
  185.      * </p>
  186.      * @param order derivation order for the vector components (must be either 0, 1 or 2)
  187.      * @return vector with time-derivatives embedded within the coordinates
  188.      * @exception OrekitException if the user specified order is too large
  189.      */
  190.     public FieldVector3D<DerivativeStructure> toDerivativeStructureVector(final int order)
  191.         throws OrekitException {

  192.         final DSFactory factory;
  193.         final DerivativeStructure x;
  194.         final DerivativeStructure y;
  195.         final DerivativeStructure z;
  196.         switch(order) {
  197.             case 0 :
  198.                 factory = new DSFactory(1, order);
  199.                 x = factory.build(position.getX());
  200.                 y = factory.build(position.getY());
  201.                 z = factory.build(position.getZ());
  202.                 break;
  203.             case 1 :
  204.                 factory = new DSFactory(1, order);
  205.                 x = factory.build(position.getX(), velocity.getX());
  206.                 y = factory.build(position.getY(), velocity.getY());
  207.                 z = factory.build(position.getZ(), velocity.getZ());
  208.                 break;
  209.             case 2 :
  210.                 factory = new DSFactory(1, order);
  211.                 x = factory.build(position.getX(), velocity.getX(), acceleration.getX());
  212.                 y = factory.build(position.getY(), velocity.getY(), acceleration.getY());
  213.                 z = factory.build(position.getZ(), velocity.getZ(), acceleration.getZ());
  214.                 break;
  215.             default :
  216.                 throw new OrekitException(OrekitMessages.OUT_OF_RANGE_DERIVATION_ORDER, order);
  217.         }

  218.         return new FieldVector3D<>(x, y, z);

  219.     }

  220.     /** Transform the instance to a {@link FieldPVCoordinates}&lt;{@link DerivativeStructure}&gt;.
  221.      * <p>
  222.      * The {@link DerivativeStructure} coordinates correspond to time-derivatives up
  223.      * to the user-specified order. As both the instance components {@link #getPosition() position},
  224.      * {@link #getVelocity() velocity} and {@link #getAcceleration() acceleration} and the
  225.      * {@link DerivativeStructure#getPartialDerivative(int...) derivatives} of the components
  226.      * holds time-derivatives, there are several ways to retrieve these derivatives. If for example
  227.      * the {@code order} is set to 2, then both {@code pv.getPosition().getX().getPartialDerivative(2)},
  228.      * {@code pv.getVelocity().getX().getPartialDerivative(1)} and
  229.      * {@code pv.getAcceleration().getX().getValue()} return the exact same value.
  230.      * </p>
  231.      * <p>
  232.      * If derivation order is 1, the first derivative of acceleration will be computed as a
  233.      * Keplerian-only jerk. If derivation order is 2, the second derivative of velocity (which
  234.      * is also the first derivative of acceleration) will be computed as a Keplerian-only jerk,
  235.      * and the second derivative of acceleration will be computed as a Keplerian-only jounce.
  236.      * </p>
  237.      * @param order derivation order for the vector components (must be either 0, 1 or 2)
  238.      * @return pv coordinates with time-derivatives embedded within the coordinates
  239.      * @exception OrekitException if the user specified order is too large
  240.      * @since 9.2
  241.      */
  242.     public FieldPVCoordinates<DerivativeStructure> toDerivativeStructurePV(final int order)
  243.         throws OrekitException {

  244.         final DSFactory factory;
  245.         final DerivativeStructure x0;
  246.         final DerivativeStructure y0;
  247.         final DerivativeStructure z0;
  248.         final DerivativeStructure x1;
  249.         final DerivativeStructure y1;
  250.         final DerivativeStructure z1;
  251.         final DerivativeStructure x2;
  252.         final DerivativeStructure y2;
  253.         final DerivativeStructure z2;
  254.         switch(order) {
  255.             case 0 :
  256.                 factory = new DSFactory(1, order);
  257.                 x0 = factory.build(position.getX());
  258.                 y0 = factory.build(position.getY());
  259.                 z0 = factory.build(position.getZ());
  260.                 x1 = factory.build(velocity.getX());
  261.                 y1 = factory.build(velocity.getY());
  262.                 z1 = factory.build(velocity.getZ());
  263.                 x2 = factory.build(acceleration.getX());
  264.                 y2 = factory.build(acceleration.getY());
  265.                 z2 = factory.build(acceleration.getZ());
  266.                 break;
  267.             case 1 : {
  268.                 factory = new DSFactory(1, order);
  269.                 final double   r2            = position.getNormSq();
  270.                 final double   r             = FastMath.sqrt(r2);
  271.                 final double   pvOr2         = Vector3D.dotProduct(position, velocity) / r2;
  272.                 final double   a             = acceleration.getNorm();
  273.                 final double   aOr           = a / r;
  274.                 final Vector3D keplerianJerk = new Vector3D(-3 * pvOr2, acceleration, -aOr, velocity);
  275.                 x0 = factory.build(position.getX(),     velocity.getX());
  276.                 y0 = factory.build(position.getY(),     velocity.getY());
  277.                 z0 = factory.build(position.getZ(),     velocity.getZ());
  278.                 x1 = factory.build(velocity.getX(),     acceleration.getX());
  279.                 y1 = factory.build(velocity.getY(),     acceleration.getY());
  280.                 z1 = factory.build(velocity.getZ(),     acceleration.getZ());
  281.                 x2 = factory.build(acceleration.getX(), keplerianJerk.getX());
  282.                 y2 = factory.build(acceleration.getY(), keplerianJerk.getY());
  283.                 z2 = factory.build(acceleration.getZ(), keplerianJerk.getZ());
  284.                 break;
  285.             }
  286.             case 2 : {
  287.                 factory = new DSFactory(1, order);
  288.                 final double   r2              = position.getNormSq();
  289.                 final double   r               = FastMath.sqrt(r2);
  290.                 final double   pvOr2           = Vector3D.dotProduct(position, velocity) / r2;
  291.                 final double   a               = acceleration.getNorm();
  292.                 final double   aOr             = a / r;
  293.                 final Vector3D keplerianJerk   = new Vector3D(-3 * pvOr2, acceleration, -aOr, velocity);
  294.                 final double   v2              = velocity.getNormSq();
  295.                 final double   pa              = Vector3D.dotProduct(position, acceleration);
  296.                 final double   aj              = Vector3D.dotProduct(acceleration, keplerianJerk);
  297.                 final Vector3D keplerianJounce = new Vector3D(-3 * (v2 + pa) / r2 + 15 * pvOr2 * pvOr2 - aOr, acceleration,
  298.                                                               4 * aOr * pvOr2 - aj / (a * r), velocity);
  299.                 x0 = factory.build(position.getX(),     velocity.getX(),      acceleration.getX());
  300.                 y0 = factory.build(position.getY(),     velocity.getY(),      acceleration.getY());
  301.                 z0 = factory.build(position.getZ(),     velocity.getZ(),      acceleration.getZ());
  302.                 x1 = factory.build(velocity.getX(),     acceleration.getX(),  keplerianJerk.getX());
  303.                 y1 = factory.build(velocity.getY(),     acceleration.getY(),  keplerianJerk.getY());
  304.                 z1 = factory.build(velocity.getZ(),     acceleration.getZ(),  keplerianJerk.getZ());
  305.                 x2 = factory.build(acceleration.getX(), keplerianJerk.getX(), keplerianJounce.getX());
  306.                 y2 = factory.build(acceleration.getY(), keplerianJerk.getY(), keplerianJounce.getY());
  307.                 z2 = factory.build(acceleration.getZ(), keplerianJerk.getZ(), keplerianJounce.getZ());
  308.                 break;
  309.             }
  310.             default :
  311.                 throw new OrekitException(OrekitMessages.OUT_OF_RANGE_DERIVATION_ORDER, order);
  312.         }

  313.         return new FieldPVCoordinates<>(new FieldVector3D<>(x0, y0, z0),
  314.                                         new FieldVector3D<>(x1, y1, z1),
  315.                                         new FieldVector3D<>(x2, y2, z2));

  316.     }

  317.     /** Estimate velocity between two positions.
  318.      * <p>Estimation is based on a simple fixed velocity translation
  319.      * during the time interval between the two positions.</p>
  320.      * @param start start position
  321.      * @param end end position
  322.      * @param dt time elapsed between the dates of the two positions
  323.      * @return velocity allowing to go from start to end positions
  324.      */
  325.     public static Vector3D estimateVelocity(final Vector3D start, final Vector3D end, final double dt) {
  326.         final double scale = 1.0 / dt;
  327.         return new Vector3D(scale, end, -scale, start);
  328.     }

  329.     /** Get a time-shifted state.
  330.      * <p>
  331.      * The state can be slightly shifted to close dates. This shift is based on
  332.      * a simple Taylor expansion. It is <em>not</em> intended as a replacement for
  333.      * proper orbit propagation (it is not even Keplerian!) but should be sufficient
  334.      * for either small time shifts or coarse accuracy.
  335.      * </p>
  336.      * @param dt time shift in seconds
  337.      * @return a new state, shifted with respect to the instance (which is immutable)
  338.      */
  339.     public PVCoordinates shiftedBy(final double dt) {
  340.         return new PVCoordinates(new Vector3D(1, position, dt, velocity, 0.5 * dt * dt, acceleration),
  341.                                  new Vector3D(1, velocity, dt, acceleration),
  342.                                  acceleration);
  343.     }

  344.     /** Gets the position.
  345.      * @return the position vector (m).
  346.      */
  347.     public Vector3D getPosition() {
  348.         return position;
  349.     }

  350.     /** Gets the velocity.
  351.      * @return the velocity vector (m/s).
  352.      */
  353.     public Vector3D getVelocity() {
  354.         return velocity;
  355.     }

  356.     /** Gets the acceleration.
  357.      * @return the acceleration vector (m/s²).
  358.      */
  359.     public Vector3D getAcceleration() {
  360.         return acceleration;
  361.     }

  362.     /** Gets the momentum.
  363.      * <p>This vector is the p &otimes; v where p is position, v is velocity
  364.      * and &otimes; is cross product. To get the real physical angular momentum
  365.      * you need to multiply this vector by the mass.</p>
  366.      * <p>The returned vector is recomputed each time this method is called, it
  367.      * is not cached.</p>
  368.      * @return a new instance of the momentum vector (m²/s).
  369.      */
  370.     public Vector3D getMomentum() {
  371.         return Vector3D.crossProduct(position, velocity);
  372.     }

  373.     /**
  374.      * Get the angular velocity (spin) of this point as seen from the origin.
  375.      *
  376.      * <p> The angular velocity vector is parallel to the {@link #getMomentum()
  377.      * angular momentum} and is computed by ω = p &times; v / ||p||²
  378.      *
  379.      * @return the angular velocity vector
  380.      * @see <a href="http://en.wikipedia.org/wiki/Angular_velocity">Angular Velocity on
  381.      *      Wikipedia</a>
  382.      */
  383.     public Vector3D getAngularVelocity() {
  384.         return this.getMomentum().scalarMultiply(1.0 / this.getPosition().getNormSq());
  385.     }

  386.     /** Get the opposite of the instance.
  387.      * @return a new position-velocity which is opposite to the instance
  388.      */
  389.     public PVCoordinates negate() {
  390.         return new PVCoordinates(position.negate(), velocity.negate(), acceleration.negate());
  391.     }

  392.     /** Normalize the position part of the instance.
  393.      * <p>
  394.      * The computed coordinates first component (position) will be a
  395.      * normalized vector, the second component (velocity) will be the
  396.      * derivative of the first component (hence it will generally not
  397.      * be normalized), and the third component (acceleration) will be the
  398.      * derivative of the second component (hence it will generally not
  399.      * be normalized).
  400.      * </p>
  401.      * @return a new instance, with first component normalized and
  402.      * remaining component computed to have consistent derivatives
  403.      */
  404.     public PVCoordinates normalize() {
  405.         final double   inv     = 1.0 / position.getNorm();
  406.         final Vector3D u       = new Vector3D(inv, position);
  407.         final Vector3D v       = new Vector3D(inv, velocity);
  408.         final Vector3D w       = new Vector3D(inv, acceleration);
  409.         final double   uv      = Vector3D.dotProduct(u, v);
  410.         final double   v2      = Vector3D.dotProduct(v, v);
  411.         final double   uw      = Vector3D.dotProduct(u, w);
  412.         final Vector3D uDot    = new Vector3D(1, v, -uv, u);
  413.         final Vector3D uDotDot = new Vector3D(1, w, -2 * uv, v, 3 * uv * uv - v2 - uw, u);
  414.         return new PVCoordinates(u, uDot, uDotDot);
  415.     }

  416.     /** Compute the cross-product of two instances.
  417.      * @param pv1 first instances
  418.      * @param pv2 second instances
  419.      * @return the cross product v1 ^ v2 as a new instance
  420.      */
  421.     public static PVCoordinates crossProduct(final PVCoordinates pv1, final PVCoordinates pv2) {
  422.         final Vector3D p1 = pv1.position;
  423.         final Vector3D v1 = pv1.velocity;
  424.         final Vector3D a1 = pv1.acceleration;
  425.         final Vector3D p2 = pv2.position;
  426.         final Vector3D v2 = pv2.velocity;
  427.         final Vector3D a2 = pv2.acceleration;
  428.         return new PVCoordinates(Vector3D.crossProduct(p1, p2),
  429.                                  new Vector3D(1, Vector3D.crossProduct(p1, v2),
  430.                                               1, Vector3D.crossProduct(v1, p2)),
  431.                                  new Vector3D(1, Vector3D.crossProduct(p1, a2),
  432.                                               2, Vector3D.crossProduct(v1, v2),
  433.                                               1, Vector3D.crossProduct(a1, p2)));
  434.     }

  435.     /** Return a string representation of this position/velocity pair.
  436.      * @return string representation of this position/velocity pair
  437.      */
  438.     public String toString() {
  439.         final String comma = ", ";
  440.         return new StringBuffer().append('{').append("P(").
  441.                 append(position.getX()).append(comma).
  442.                 append(position.getY()).append(comma).
  443.                 append(position.getZ()).append("), V(").
  444.                 append(velocity.getX()).append(comma).
  445.                 append(velocity.getY()).append(comma).
  446.                 append(velocity.getZ()).append("), A(").
  447.                 append(acceleration.getX()).append(comma).
  448.                 append(acceleration.getY()).append(comma).
  449.                 append(acceleration.getZ()).append(")}").toString();
  450.     }

  451.     /** Replace the instance with a data transfer object for serialization.
  452.      * @return data transfer object that will be serialized
  453.      */
  454.     private Object writeReplace() {
  455.         return new DTO(this);
  456.     }

  457.     /** Internal class used only for serialization. */
  458.     private static class DTO implements Serializable {

  459.         /** Serializable UID. */
  460.         private static final long serialVersionUID = 20140723L;

  461.         /** Double values. */
  462.         private double[] d;

  463.         /** Simple constructor.
  464.          * @param pv instance to serialize
  465.          */
  466.         private DTO(final PVCoordinates pv) {
  467.             this.d = new double[] {
  468.                 pv.getPosition().getX(),     pv.getPosition().getY(),     pv.getPosition().getZ(),
  469.                 pv.getVelocity().getX(),     pv.getVelocity().getY(),     pv.getVelocity().getZ(),
  470.                 pv.getAcceleration().getX(), pv.getAcceleration().getY(), pv.getAcceleration().getZ(),
  471.             };
  472.         }

  473.         /** Replace the deserialized data transfer object with a {@link PVCoordinates}.
  474.          * @return replacement {@link PVCoordinates}
  475.          */
  476.         private Object readResolve() {
  477.             return new PVCoordinates(new Vector3D(d[0], d[1], d[2]),
  478.                                      new Vector3D(d[3], d[4], d[5]),
  479.                                      new Vector3D(d[6], d[7], d[8]));
  480.         }

  481.     }

  482. }