ReferenceEllipsoid.java

  1. /* Contributed in the public domain.
  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.models.earth;

  18. import org.hipparchus.util.FastMath;
  19. import org.orekit.bodies.OneAxisEllipsoid;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.utils.Constants;

  22. /**
  23.  * A Reference Ellipsoid for use in geodesy. The ellipsoid defines an
  24.  * ellipsoidal potential called the normal potential, and its gradient, normal
  25.  * gravity.
  26.  *
  27.  * <p> These parameters are needed to define the normal potential:
  28.  *
  29.  *
  30.  * <ul> <li>a, semi-major axis</li>
  31.  *
  32.  * <li>f, flattening</li>
  33.  *
  34.  * <li>GM, the gravitational parameter</li>
  35.  *
  36.  * <li>&omega;, the spin rate</li> </ul>
  37.  *
  38.  * <p> References:
  39.  *
  40.  * <ol> <li>Martin Losch, Verena Seufer. How to Compute Geoid Undulations (Geoid
  41.  * Height Relative to a Given Reference Ellipsoid) from Spherical Harmonic
  42.  * Coefficients for Satellite Altimetry Applications. , 2003. <a
  43.  * href="mitgcm.org/~mlosch/geoidcookbook.pdf" >mitgcm.org/~mlosch/geoidcookbook.pdf</a></li>
  44.  *
  45.  * <li>Weikko A. Heiskanen, Helmut Moritz. Physical Geodesy. W. H. Freeman and
  46.  * Company, 1967. (especially sections 2.13 and equation 2-144)</li>
  47.  *
  48.  * <li>Department of Defense World Geodetic System 1984. 2000. NIMA TR 8350.2
  49.  * Third Edition, Amendment 1.</li> </ol>
  50.  *
  51.  * @author Evan Ward
  52.  */
  53. public class ReferenceEllipsoid extends OneAxisEllipsoid implements EarthShape {

  54.     /** uid is date of last modification. */
  55.     private static final long serialVersionUID = 20150311L;

  56.     /** the gravitational parameter of the ellipsoid, in m<sup>3</sup>/s<sup>2</sup>. */
  57.     private final double GM;
  58.     /** the rotation rate of the ellipsoid, in rad/s. */
  59.     private final double spin;

  60.     /**
  61.      * Creates a new geodetic Reference Ellipsoid from four defining
  62.      * parameters.
  63.      *
  64.      * @param ae        Equatorial radius, in m
  65.      * @param f         flattening of the ellipsoid.
  66.      * @param bodyFrame the frame to attach to the ellipsoid. The origin is at
  67.      *                  the center of mass, the z axis is the minor axis.
  68.      * @param GM        gravitational parameter, in m<sup>3</sup>/s<sup>2</sup>
  69.      * @param spin      &omega; in rad/s
  70.      */
  71.     public ReferenceEllipsoid(final double ae,
  72.                               final double f,
  73.                               final Frame bodyFrame,
  74.                               final double GM,
  75.                               final double spin) {
  76.         super(ae, f, bodyFrame);
  77.         this.GM = GM;
  78.         this.spin = spin;
  79.     }

  80.     /**
  81.      * Gets the gravitational parameter that is part of the definition of the
  82.      * reference ellipsoid.
  83.      *
  84.      * @return GM in m<sup>3</sup>/s<sup>2</sup>
  85.      */
  86.     public double getGM() {
  87.         return this.GM;
  88.     }

  89.     /**
  90.      * Gets the rotation of the ellipsoid about its axis.
  91.      *
  92.      * @return &omega; in rad/s
  93.      */
  94.     public double getSpin() {
  95.         return this.spin;
  96.     }

  97.     /**
  98.      * Get the radius of this ellipsoid at the poles.
  99.      *
  100.      * @return the polar radius, in meters
  101.      * @see #getEquatorialRadius()
  102.      */
  103.     public double getPolarRadius() {
  104.         // use the definition of flattening: f = (a-b)/a
  105.         final double a = this.getEquatorialRadius();
  106.         final double f = this.getFlattening();
  107.         return a - f * a;
  108.     }

  109.     /**
  110.      * Gets the normal gravity, that is gravity just due to the reference
  111.      * ellipsoid's potential. The normal gravity only depends on latitude
  112.      * because the ellipsoid is axis symmetric.
  113.      *
  114.      * <p> The normal gravity is a vector, having both magnitude and direction.
  115.      * This method only give the magnitude.
  116.      *
  117.      * @param latitude geodetic latitude, in radians. That is the angle between
  118.      *                 the local normal on the ellipsoid and the equatorial
  119.      *                 plane.
  120.      * @return the normal gravity, &gamma;, at the given latitude in
  121.      * m/s<sup>2</sup>. This is the acceleration felt by a mass at rest on the
  122.      * surface of the reference ellipsoid.
  123.      */
  124.     public double getNormalGravity(final double latitude) {
  125.         /*
  126.          * Uses the equations from [2] as compiled in [1]. See Class comment.
  127.          */

  128.         final double a  = this.getEquatorialRadius();
  129.         final double f  = this.getFlattening();

  130.         // define derived constants, move to constructor for more speed
  131.         // semi-minor axis
  132.         final double b = a * (1 - f);
  133.         final double a2 = a * a;
  134.         final double b2 = b * b;
  135.         // linear eccentricity
  136.         final double E = FastMath.sqrt(a2 - b2);
  137.         // first numerical eccentricity
  138.         final double e = E / a;
  139.         // second numerical eccentricity
  140.         final double eprime = E / b;
  141.         // an abbreviation for a common term
  142.         final double m = this.spin * this.spin * a2 * b / this.GM;
  143.         // gravity at equator
  144.         final double ya = this.GM / (a * b) *
  145.                 (1 - 3. / 2. * m - 3. / 14. * eprime * m);
  146.         // gravity at the poles
  147.         final double yb = this.GM / a2 * (1 + m + 3. / 7. * eprime * m);
  148.         // another abbreviation for a common term
  149.         final double kappa = (b * yb - a * ya) / (a * ya);

  150.         // calculate normal gravity at the given latitude.
  151.         final double sin  = FastMath.sin(latitude);
  152.         final double sin2 = sin * sin;
  153.         return ya * (1 + kappa * sin2) / FastMath.sqrt(1 - e * e * sin2);
  154.     }

  155.     /**
  156.      * Get the fully normalized coefficient C<sub>2n,0</sub> for the normal
  157.      * gravity potential.
  158.      *
  159.      * @param n index in C<sub>2n,0</sub>, n &gt;= 1.
  160.      * @return normalized C<sub>2n,0</sub> of the ellipsoid
  161.      * @see "Department of Defense World Geodetic System 1984. 2000. NIMA TR
  162.      * 8350.2 Third Edition, Amendment 1."
  163.      * @see "DMA TR 8350.2. 1984."
  164.      */
  165.     public double getC2n0(final int n) {
  166.         // parameter check
  167.         if (n < 1) {
  168.             throw new IllegalArgumentException("Expected n < 1, got n=" + n);
  169.         }

  170.         final double a = this.getEquatorialRadius();
  171.         final double f = this.getFlattening();
  172.         // define derived constants, move to constructor for more speed
  173.         // semi-minor axis
  174.         final double b = a * (1 - f);
  175.         final double a2 = a * a;
  176.         final double b2 = b * b;
  177.         // linear eccentricity
  178.         final double E = FastMath.sqrt(a2 - b2);
  179.         // first numerical eccentricity
  180.         final double e = E / a;
  181.         // an abbreviation for a common term
  182.         final double m = this.spin * this.spin * a2 * b / this.GM;

  183.         /*
  184.          * derive C2 using a linear approximation, good to ~1e-9, eq 2.118 in
  185.          * Heiskanen & Moritz[2]. See comment for ReferenceEllipsoid
  186.          */
  187.         final double J2 = 2. / 3. * f - 1. / 3. * m - 1. / 3. * f * f + 2. / 21. * f * m;
  188.         final double C2 = -J2 / FastMath.sqrt(5);

  189.         // eq 3-62 in chapter 3 of DMA TR 8350.2, calculated by scaling C2,0
  190.         return (((n & 0x1) == 0) ? 3 : -3) * FastMath.pow(e, 2 * n) *
  191.                 (1 - n - FastMath.pow(5, 3. / 2.) * n * C2 / (e * e)) /
  192.                 ((2 * n + 1) * (2 * n + 3) * FastMath.sqrt(4 * n + 1));
  193.     }

  194.     @Override
  195.     public ReferenceEllipsoid getEllipsoid() {
  196.         return this;
  197.     }

  198.     /**
  199.      * Get the WGS84 ellipsoid, attached to the given body frame.
  200.      *
  201.      * @param bodyFrame the earth centered fixed frame
  202.      * @return a WGS84 reference ellipsoid
  203.      */
  204.     public static ReferenceEllipsoid getWgs84(final Frame bodyFrame) {
  205.         return new ReferenceEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
  206.                 Constants.WGS84_EARTH_FLATTENING, bodyFrame,
  207.                 Constants.WGS84_EARTH_MU,
  208.                 Constants.WGS84_EARTH_ANGULAR_VELOCITY);
  209.     }

  210.     /**
  211.      * Get the GRS80 ellipsoid, attached to the given body frame.
  212.      *
  213.      * @param bodyFrame the earth centered fixed frame
  214.      * @return a GRS80 reference ellipsoid
  215.      */
  216.     public static ReferenceEllipsoid getGrs80(final Frame bodyFrame) {
  217.         return new ReferenceEllipsoid(
  218.                 Constants.GRS80_EARTH_EQUATORIAL_RADIUS,
  219.                 Constants.GRS80_EARTH_FLATTENING,
  220.                 bodyFrame,
  221.                 Constants.GRS80_EARTH_MU,
  222.                 Constants.GRS80_EARTH_ANGULAR_VELOCITY
  223.         );
  224.     }

  225. }