OrbitType.java

  1. /* Copyright 2002-2016 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.orbits;

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

  23. /** Enumerate for {@link Orbit orbital} parameters types.
  24.  */
  25. public enum OrbitType {

  26.     /** Type for propagation in {@link CartesianOrbit Cartesian parameters}. */
  27.     CARTESIAN {

  28.         /** {@inheritDoc} */
  29.         public Orbit convertType(final Orbit orbit) {
  30.             return (orbit.getType() == this) ? orbit : new CartesianOrbit(orbit);
  31.         }

  32.         /** {@inheritDoc} */
  33.         public void mapOrbitToArray(final Orbit orbit, final PositionAngle type,
  34.                                     final double[] stateVector) {

  35.             final PVCoordinates pv = orbit.getPVCoordinates();
  36.             final Vector3D      p  = pv.getPosition();
  37.             final Vector3D      v  = pv.getVelocity();

  38.             stateVector[0] = p.getX();
  39.             stateVector[1] = p.getY();
  40.             stateVector[2] = p.getZ();
  41.             stateVector[3] = v.getX();
  42.             stateVector[4] = v.getY();
  43.             stateVector[5] = v.getZ();

  44.         }

  45.         /** {@inheritDoc} */
  46.         public Orbit mapArrayToOrbit(final double[] stateVector, final PositionAngle type,
  47.                                      final AbsoluteDate date, final double mu, final Frame frame) {

  48.             final Vector3D p     = new Vector3D(stateVector[0], stateVector[1], stateVector[2]);
  49.             final double r2      = p.getNormSq();
  50.             final Vector3D v     = new Vector3D(stateVector[3], stateVector[4], stateVector[5]);
  51.             final Vector3D a     = new Vector3D(-mu / (r2 * FastMath.sqrt(r2)), p);
  52.             return new CartesianOrbit(new PVCoordinates(p, v, a), frame, date, mu);

  53.         }

  54.     },

  55.     /** Type for propagation in {@link CircularOrbit circular parameters}. */
  56.     CIRCULAR {

  57.         /** {@inheritDoc} */
  58.         public Orbit convertType(final Orbit orbit) {
  59.             return (orbit.getType() == this) ? orbit : new CircularOrbit(orbit);
  60.         }

  61.         /** {@inheritDoc} */
  62.         public void mapOrbitToArray(final Orbit orbit, final PositionAngle type,
  63.                                     final double[] stateVector) {

  64.             final CircularOrbit circularOrbit = (CircularOrbit) OrbitType.CIRCULAR.convertType(orbit);

  65.             stateVector[0] = circularOrbit.getA();
  66.             stateVector[1] = circularOrbit.getCircularEx();
  67.             stateVector[2] = circularOrbit.getCircularEy();
  68.             stateVector[3] = circularOrbit.getI();
  69.             stateVector[4] = circularOrbit.getRightAscensionOfAscendingNode();
  70.             stateVector[5] = circularOrbit.getAlpha(type);

  71.         }

  72.         /** {@inheritDoc} */
  73.         public Orbit mapArrayToOrbit(final double[] stateVector, final PositionAngle type,
  74.                                      final AbsoluteDate date, final double mu, final Frame frame) {
  75.             return new CircularOrbit(stateVector[0], stateVector[1], stateVector[2], stateVector[3],
  76.                                      stateVector[4], stateVector[5], type,
  77.                                      frame, date, mu);
  78.         }

  79.     },

  80.     /** Type for propagation in {@link EquinoctialOrbit equinoctial parameters}. */
  81.     EQUINOCTIAL {

  82.         /** {@inheritDoc} */
  83.         public Orbit convertType(final Orbit orbit) {
  84.             return (orbit.getType() == this) ? orbit : new EquinoctialOrbit(orbit);
  85.         }

  86.         /** {@inheritDoc} */
  87.         public void mapOrbitToArray(final Orbit orbit, final PositionAngle type,
  88.                                     final double[] stateVector) {

  89.             final EquinoctialOrbit equinoctialOrbit =
  90.                 (EquinoctialOrbit) OrbitType.EQUINOCTIAL.convertType(orbit);

  91.             stateVector[0] = equinoctialOrbit.getA();
  92.             stateVector[1] = equinoctialOrbit.getEquinoctialEx();
  93.             stateVector[2] = equinoctialOrbit.getEquinoctialEy();
  94.             stateVector[3] = equinoctialOrbit.getHx();
  95.             stateVector[4] = equinoctialOrbit.getHy();
  96.             stateVector[5] = equinoctialOrbit.getL(type);

  97.         }

  98.         /** {@inheritDoc} */
  99.         public Orbit mapArrayToOrbit(final double[] stateVector, final PositionAngle type,
  100.                                      final AbsoluteDate date, final double mu, final Frame frame) {
  101.             return new EquinoctialOrbit(stateVector[0], stateVector[1], stateVector[2], stateVector[3],
  102.                                         stateVector[4], stateVector[5], type,
  103.                                         frame, date, mu);
  104.         }

  105.     },

  106.     /** Type for propagation in {@link KeplerianOrbit Keplerian parameters}. */
  107.     KEPLERIAN {

  108.         /** {@inheritDoc} */
  109.         public Orbit convertType(final Orbit orbit) {
  110.             return (orbit.getType() == this) ? orbit : new KeplerianOrbit(orbit);
  111.         }

  112.         /** {@inheritDoc} */
  113.         public void mapOrbitToArray(final Orbit orbit, final PositionAngle type,
  114.                                     final double[] stateVector) {

  115.             final KeplerianOrbit keplerianOrbit =
  116.                 (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(orbit);

  117.             stateVector[0] = keplerianOrbit.getA();
  118.             stateVector[1] = keplerianOrbit.getE();
  119.             stateVector[2] = keplerianOrbit.getI();
  120.             stateVector[3] = keplerianOrbit.getPerigeeArgument();
  121.             stateVector[4] = keplerianOrbit.getRightAscensionOfAscendingNode();
  122.             stateVector[5] = keplerianOrbit.getAnomaly(type);

  123.         }

  124.         /** {@inheritDoc} */
  125.         public Orbit mapArrayToOrbit(final double[] stateVector, final PositionAngle type,
  126.                                      final AbsoluteDate date, final double mu, final Frame frame) {
  127.             return new KeplerianOrbit(stateVector[0], stateVector[1], stateVector[2], stateVector[3],
  128.                                       stateVector[4], stateVector[5], type,
  129.                                       frame, date, mu);
  130.         }

  131.     };

  132.     /** Convert an orbit to the instance type.
  133.      * <p>
  134.      * The returned orbit is the specified instance itself if its type already matches,
  135.      * otherwise, a new orbit of the proper type created
  136.      * </p>
  137.      * @param orbit orbit to convert
  138.      * @return converted orbit with type guaranteed to match (so it can be cast safely)
  139.      */
  140.     public abstract Orbit convertType(final Orbit orbit);

  141.     /** Convert orbit to state array.
  142.      * <p>
  143.      * Note that all implementations of this method <em>must</em> be consistent with the
  144.      * implementation of the {@link org.orekit.orbits.Orbit#getJacobianWrtCartesian(
  145.      * org.orekit.orbits.PositionAngle, double[][]) Orbit.getJacobianWrtCartesian}
  146.      * method for the corresponding orbit type in terms of parameters order and meaning.
  147.      * </p>
  148.      * @param orbit orbit to map
  149.      * @param type type of the angle
  150.      * @param stateVector flat array into which the state vector should be mapped
  151.      * (it can have more than 6 elements, extra elements are untouched)
  152.      */
  153.     public abstract void mapOrbitToArray(Orbit orbit, PositionAngle type, double[] stateVector);

  154.      /** Convert state array to orbital parameters.
  155.      * <p>
  156.      * Note that all implementations of this method <em>must</em> be consistent with the
  157.      * implementation of the {@link org.orekit.orbits.Orbit#getJacobianWrtCartesian(
  158.      * org.orekit.orbits.PositionAngle, double[][]) Orbit.getJacobianWrtCartesian}
  159.      * method for the corresponding orbit type in terms of parameters order and meaning.
  160.      * </p>
  161.      * @param array state as a flat array
  162.      * (it can have more than 6 elements, extra elements are ignored)
  163.      * @param type type of the angle
  164.      * @param date integration date
  165.      * @param mu central attraction coefficient used for propagation (m³/s²)
  166.      * @param frame frame in which integration is performed
  167.      * @return orbit corresponding to the flat array as a space dynamics object
  168.      */
  169.     public abstract Orbit mapArrayToOrbit(double[] array, PositionAngle type,
  170.                                           AbsoluteDate date, double mu, Frame frame);

  171. }