PosVelChebyshev.java

  1. /* Copyright 2002-2013 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.bodies;

  18. import java.io.Serializable;

  19. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  20. import org.apache.commons.math3.util.FastMath;
  21. import org.orekit.time.AbsoluteDate;
  22. import org.orekit.time.TimeStamped;
  23. import org.orekit.utils.PVCoordinates;


  24. /** Position-Velocity model based on Chebyshev polynomials.
  25.  * <p>This class represent the most basic element of the piecewise ephemerides
  26.  * for solar system bodies like JPL DE 405 ephemerides.</p>
  27.  * @see JPLEphemeridesLoader
  28.  * @author Luc Maisonobe
  29.  */
  30. class PosVelChebyshev implements TimeStamped, Serializable {

  31.     /** Serializable UID. */
  32.     private static final long serialVersionUID = -2220448511466595393L;

  33.     /** Start of the validity range of the instance. */
  34.     private final AbsoluteDate start;

  35.     /** Duration of validity range of the instance. */
  36.     private final double duration;

  37.     /** Chebyshev polynomials coefficients for the X component. */
  38.     private final double[] xCoeffs;

  39.     /** Chebyshev polynomials coefficients for the Y component. */
  40.     private final double[] yCoeffs;

  41.     /** Chebyshev polynomials coefficients for the Z component. */
  42.     private final double[] zCoeffs;

  43.     /** Simple constructor.
  44.      * @param start start of the validity range of the instance
  45.      * @param duration duration of the validity range of the instance
  46.      * @param xCoeffs Chebyshev polynomials coefficients for the X component
  47.      * (a reference to the array will be stored in the instance)
  48.      * @param yCoeffs Chebyshev polynomials coefficients for the Y component
  49.      * (a reference to the array will be stored in the instance)
  50.      * @param zCoeffs Chebyshev polynomials coefficients for the Z component
  51.      * (a reference to the array will be stored in the instance)
  52.      */
  53.     public PosVelChebyshev(final AbsoluteDate start, final double duration,
  54.                            final double[] xCoeffs, final double[] yCoeffs,
  55.                            final double[] zCoeffs) {
  56.         this.start    = start;
  57.         this.duration = duration;
  58.         this.xCoeffs  = xCoeffs;
  59.         this.yCoeffs  = yCoeffs;
  60.         this.zCoeffs  = zCoeffs;
  61.     }

  62.     /** {@inheritDoc} */
  63.     public AbsoluteDate getDate() {
  64.         return start;
  65.     }

  66.     /** Get model validity duration.
  67.      * @return model validity duration in seconds
  68.      */
  69.     public double getValidityDuration() {
  70.         return duration;
  71.     }

  72.     /** Check if the instance is the exact successor of another model.
  73.      * <p>The instance is the successor of another model if its start
  74.      * date is within a 1ms tolerance interval of the end date of the
  75.      * other model.</p>
  76.      * @param predecessor model to check instance against
  77.      * @return true if the instance is the successor of the predecessor model
  78.      */
  79.     public boolean isSuccessorOf(final PosVelChebyshev predecessor) {
  80.         final double gap = start.durationFrom(predecessor.start) - predecessor.duration;
  81.         return FastMath.abs(gap) < 0.001;
  82.     }

  83.     /** Check if a date is in validity range.
  84.      * @param date date to check
  85.      * @return true if date is in validity range
  86.      */
  87.     public boolean inRange(final AbsoluteDate date) {
  88.         final double dt = date.durationFrom(start);
  89.         return (dt >= -0.001) && (dt <= duration + 0.001);
  90.     }

  91.     /** Get the position-velocity at a specified date.
  92.      * @param date date at which position-velocity is requested
  93.      * @return position-velocity at specified date
  94.      */
  95.     public PVCoordinates getPositionVelocity(final AbsoluteDate date) {

  96.         // normalize date
  97.         final double t = (2 * date.durationFrom(start) - duration) / duration;
  98.         final double twoT = 2 * t;

  99.         // initialize Chebyshev polynomials recursion
  100.         double pKm1 = 1;
  101.         double pK   = t;
  102.         double xP   = xCoeffs[0];
  103.         double yP   = yCoeffs[0];
  104.         double zP   = zCoeffs[0];

  105.         // initialize Chebishev polynomials derivatives recursion
  106.         double qKm1 = 0;
  107.         double qK   = 1;
  108.         double xV   = 0;
  109.         double yV   = 0;
  110.         double zV   = 0;

  111.         // combine polynomials by applying coefficients
  112.         for (int k = 1; k < xCoeffs.length; ++k) {

  113.             // consider last computed polynomials on position
  114.             xP += xCoeffs[k] * pK;
  115.             yP += yCoeffs[k] * pK;
  116.             zP += zCoeffs[k] * pK;

  117.             // consider last computed polynomials on velocity
  118.             xV += xCoeffs[k] * qK;
  119.             yV += yCoeffs[k] * qK;
  120.             zV += zCoeffs[k] * qK;

  121.             // compute next Chebyshev polynomial value
  122.             final double pKm2 = pKm1;
  123.             pKm1 = pK;
  124.             pK   = twoT * pKm1 - pKm2;

  125.             // compute next Chebyshev polynomial derivative
  126.             final double qKm2 = qKm1;
  127.             qKm1 = qK;
  128.             qK   = twoT * qKm1 + 2 * pKm1 - qKm2;

  129.         }

  130.         final double vScale = 2 / duration;
  131.         return new PVCoordinates(new Vector3D(xP, yP, zP),
  132.                                  new Vector3D(xV * vScale, yV * vScale, zV * vScale));

  133.     }

  134. }