OrbitType.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.orbits;

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

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

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

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

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

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

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

  43.         }

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

  47.             final Vector3D p     = new Vector3D(stateVector[0], stateVector[1], stateVector[2]);
  48.             final Vector3D v     = new Vector3D(stateVector[3], stateVector[4], stateVector[5]);
  49.             return new CartesianOrbit(new PVCoordinates(p, v), frame, date, mu);

  50.         }

  51.     },

  52.     /** Type for propagation in {@link CircularOrbit circular parameters}. */
  53.     CIRCULAR {

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

  58.         /** {@inheritDoc} */
  59.         public void mapOrbitToArray(final Orbit orbit, final PositionAngle type,
  60.                                     final double[] stateVector) {

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

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

  68.         }

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

  76.     },

  77.     /** Type for propagation in {@link EquinoctialOrbit equinoctial parameters}. */
  78.     EQUINOCTIAL {

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

  83.         /** {@inheritDoc} */
  84.         public void mapOrbitToArray(final Orbit orbit, final PositionAngle type,
  85.                                     final double[] stateVector) {

  86.             final EquinoctialOrbit equinoctialOrbit =
  87.                 (EquinoctialOrbit) OrbitType.EQUINOCTIAL.convertType(orbit);

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

  94.         }

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

  102.     },

  103.     /** Type for propagation in {@link KeplerianOrbit Keplerian parameters}. */
  104.     KEPLERIAN {

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

  109.         /** {@inheritDoc} */
  110.         public void mapOrbitToArray(final Orbit orbit, final PositionAngle type,
  111.                                     final double[] stateVector) {

  112.             final KeplerianOrbit keplerianOrbit =
  113.                 (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(orbit);

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

  120.         }

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

  128.     };

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

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

  149.      /** Convert state array to orbital parameters.
  150.      * <p>
  151.      * Note that all implementations of this method <em>must</em> be consistent with the
  152.      * implementation of the {@link org.orekit.orbits.Orbit#getJacobianWrtCartesian(
  153.      * org.orekit.orbits.PositionAngle, double[][]) Orbit.getJacobianWrtCartesian}
  154.      * method for the corresponding orbit type in terms of parameters order and meaning.
  155.      * </p>
  156.      * @param array state as a flat array
  157.      * @param type type of the angle
  158.      * @param date integration date
  159.      * @param mu central attraction coefficient used for propagation (m<sup>3</sup>/s<sup>2</sup>)
  160.      * @param frame frame in which integration is performed
  161.      * @return orbit corresponding to the flat array as a space dynamics object
  162.      */
  163.     public abstract Orbit mapArrayToOrbit(double[] array, PositionAngle type,
  164.                                           AbsoluteDate date, double mu, Frame frame);

  165. }