Geoid.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.Field;
  19. import org.hipparchus.RealFieldElement;
  20. import org.hipparchus.analysis.RealFieldUnivariateFunction;
  21. import org.hipparchus.analysis.UnivariateFunction;
  22. import org.hipparchus.analysis.solvers.AllowedSolution;
  23. import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
  24. import org.hipparchus.analysis.solvers.FieldBracketingNthOrderBrentSolver;
  25. import org.hipparchus.analysis.solvers.UnivariateSolver;
  26. import org.hipparchus.exception.MathRuntimeException;
  27. import org.hipparchus.geometry.euclidean.threed.FieldLine;
  28. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  29. import org.hipparchus.geometry.euclidean.threed.Line;
  30. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  31. import org.hipparchus.util.FastMath;
  32. import org.orekit.bodies.FieldGeodeticPoint;
  33. import org.orekit.bodies.GeodeticPoint;
  34. import org.orekit.errors.OrekitException;
  35. import org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel;
  36. import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider;
  37. import org.orekit.forces.gravity.potential.TideSystem;
  38. import org.orekit.frames.FieldTransform;
  39. import org.orekit.frames.Frame;
  40. import org.orekit.frames.Transform;
  41. import org.orekit.time.AbsoluteDate;
  42. import org.orekit.time.FieldAbsoluteDate;
  43. import org.orekit.utils.TimeStampedPVCoordinates;

  44. /**
  45.  * A geoid is a level surface of the gravity potential of a body. The gravity
  46.  * potential, W, is split so W = U + T, where U is the normal potential (defined
  47.  * by the ellipsoid) and T is the anomalous potential.[3](eq. 2-137)
  48.  *
  49.  * <p> The {@link #getIntersectionPoint(Line, Vector3D, Frame, AbsoluteDate)}
  50.  * method is tailored specifically for Earth's geoid. All of the other methods
  51.  * in this class are general and will work for an arbitrary body.
  52.  *
  53.  * <p> There are several components that are needed to define a geoid[1]:
  54.  *
  55.  * <ul> <li>Geopotential field. These are the coefficients of the spherical
  56.  * harmonics: S<sub>n,m</sub> and C<sub>n,m</sub></li>
  57.  *
  58.  * <li>Reference Ellipsoid. The ellipsoid is used to define the undulation of
  59.  * the geoid (distance between ellipsoid and geoid) and U<sub>0</sub> the value
  60.  * of the normal gravity potential at the surface of the ellipsoid.</li>
  61.  *
  62.  * <li>W<sub>0</sub>, the potential at the geoid. The value of the potential on
  63.  * the level surface. This is taken to be U<sub>0</sub>, the normal gravity
  64.  * potential at the surface of the {@link ReferenceEllipsoid}.</li>
  65.  *
  66.  * <li>Permanent Tide System. This implementation assumes that the geopotential
  67.  * field and the reference ellipsoid use the same permanent tide system. If the
  68.  * assumption is false it will produce errors of about 0.5 m. Conversion between
  69.  * tide systems is a possible improvement.[1,2]</li>
  70.  *
  71.  * <li>Topographic Masses. That is mass outside of the geoid, e.g. mountains.
  72.  * This implementation ignores topographic masses, which causes up to 3m error
  73.  * in the Himalayas, and ~ 1.5m error in the Rockies. This could be improved
  74.  * through the use of DTED and calculating height anomalies or using the
  75.  * correction coefficients.[1]</li> </ul>
  76.  *
  77.  * <p> This implementation also assumes that the normal to the reference
  78.  * ellipsoid is the same as the normal to the geoid. This assumption enables the
  79.  * equation: (height above geoid) = (height above ellipsoid) - (undulation),
  80.  * which is used in {@link #transform(GeodeticPoint)} and {@link
  81.  * #transform(Vector3D, Frame, AbsoluteDate)}.
  82.  *
  83.  * <p> In testing, the error in the undulations calculated by this class were
  84.  * off by less than 3 meters, which matches the assumptions outlined above.
  85.  *
  86.  * <p> References:
  87.  *
  88.  * <ol> <li>Dru A. Smith. There is no such thing as "The" EGM96 geoid: Subtle
  89.  * points on the use of a global geopotential model. IGeS Bulletin No. 8:17-28,
  90.  * 1998. <a href= "http://www.ngs.noaa.gov/PUBS_LIB/EGM96_GEOID_PAPER/egm96_geoid_paper.html"
  91.  * >http ://www.ngs.noaa.gov/PUBS_LIB/EGM96_GEOID_PAPER/egm96_geoid_paper.html</a></li>
  92.  *
  93.  * <li> Martin Losch, Verena Seufer. How to Compute Geoid Undulations (Geoid
  94.  * Height Relative to a Given Reference Ellipsoid) from Spherical Harmonic
  95.  * Coefficients for Satellite Altimetry Applications. , 2003. <a
  96.  * href="http://mitgcm.org/~mlosch/geoidcookbook.pdf">mitgcm.org/~mlosch/geoidcookbook.pdf</a>
  97.  * </li>
  98.  *
  99.  * <li>Weikko A. Heiskanen, Helmut Moritz. Physical Geodesy. W. H. Freeman and
  100.  * Company, 1967. (especially sections 2.13 and equation 2-144 Bruns
  101.  * Formula)</li>
  102.  *
  103.  * <li>S. A. Holmes, W. E. Featherstone. A unified approach to the Clenshaw
  104.  * summation and the recursive computation of very high degree and order
  105.  * normalised associated Legendre functions. Journal of Geodesy, 76(5):279,
  106.  * 2002.</li>
  107.  *
  108.  * <li>DMA TR 8350.2. 1984.</li>
  109.  *
  110.  * <li>Department of Defense World Geodetic System 1984. 2000. NIMA TR 8350.2
  111.  * Third Edition, Amendment 1.</li> </ol>
  112.  *
  113.  * @author Evan Ward
  114.  */
  115. public class Geoid implements EarthShape {

  116.     /**
  117.      * uid is date of last modification.
  118.      */
  119.     private static final long serialVersionUID = 20150312L;

  120.     /**
  121.      * A number larger than the largest undulation. Wikipedia says the geoid
  122.      * height is in [-106, 85]. I chose 100 to be safe.
  123.      */
  124.     private static final double MAX_UNDULATION = 100;
  125.     /**
  126.      * A number smaller than the smallest undulation. Wikipedia says the geoid
  127.      * height is in [-106, 85]. I chose -150 to be safe.
  128.      */
  129.     private static final double MIN_UNDULATION = -150;
  130.     /**
  131.      * the maximum number of evaluations for the line search in {@link
  132.      * #getIntersectionPoint(Line, Vector3D, Frame, AbsoluteDate)}.
  133.      */
  134.     private static final int MAX_EVALUATIONS = 100;

  135.     /**
  136.      * the default date to use when evaluating the {@link #harmonics}. Used when
  137.      * no other dates are available. Should be removed in a future release.
  138.      */
  139.     private final AbsoluteDate defaultDate;
  140.     /**
  141.      * the reference ellipsoid.
  142.      */
  143.     private final ReferenceEllipsoid referenceEllipsoid;
  144.     /**
  145.      * the geo-potential combined with an algorithm for evaluating the spherical
  146.      * harmonics. The Holmes and Featherstone method is very robust.
  147.      */
  148.     private final transient HolmesFeatherstoneAttractionModel harmonics;

  149.     /**
  150.      * Creates a geoid from the given geopotential, reference ellipsoid and the
  151.      * assumptions in the comment for {@link Geoid}.
  152.      *
  153.      * @param geopotential       the gravity potential. Only the anomalous
  154.      *                           potential will be used. It is assumed that the
  155.      *                           {@code geopotential} and the {@code
  156.      *                           referenceEllipsoid} are defined in the same
  157.      *                           frame. Usually a {@link org.orekit.forces.gravity.potential.GravityFieldFactory#getConstantNormalizedProvider(int,
  158.      *                           int) constant geopotential} is used to define a
  159.      *                           time-invariant Geoid.
  160.      * @param referenceEllipsoid the normal gravity potential.
  161.      * @throws NullPointerException if {@code geopotential == null ||
  162.      *                              referenceEllipsoid == null}
  163.      */
  164.     public Geoid(final NormalizedSphericalHarmonicsProvider geopotential,
  165.                  final ReferenceEllipsoid referenceEllipsoid) {
  166.         // parameter check
  167.         if (geopotential == null || referenceEllipsoid == null) {
  168.             throw new NullPointerException();
  169.         }

  170.         // subtract the ellipsoid from the geopotential
  171.         final SubtractEllipsoid potential = new SubtractEllipsoid(geopotential,
  172.                 referenceEllipsoid);

  173.         // set instance parameters
  174.         this.referenceEllipsoid = referenceEllipsoid;
  175.         this.harmonics = new HolmesFeatherstoneAttractionModel(
  176.                 referenceEllipsoid.getBodyFrame(), potential);
  177.         this.defaultDate = geopotential.getReferenceDate();
  178.     }

  179.     @Override
  180.     public Frame getBodyFrame() {
  181.         // same as for reference ellipsoid.
  182.         return this.getEllipsoid().getBodyFrame();
  183.     }

  184.     /**
  185.      * Gets the Undulation of the Geoid, N at the given position. N is the
  186.      * distance between the {@link #getEllipsoid() reference ellipsoid} and the
  187.      * geoid. The latitude and longitude parameters are both defined with
  188.      * respect to the reference ellipsoid. For EGM96 and the WGS84 ellipsoid the
  189.      * undulation is between -107m and +86m.
  190.      *
  191.      * <p> NOTE: Restrictions are not put on the range of the arguments {@code
  192.      * geodeticLatitude} and {@code longitude}.
  193.      *
  194.      * @param geodeticLatitude geodetic latitude (angle between the local normal
  195.      *                         and the equatorial plane on the reference
  196.      *                         ellipsoid), in radians.
  197.      * @param longitude        on the reference ellipsoid, in radians.
  198.      * @param date             of evaluation. Used for time varying geopotential
  199.      *                         fields.
  200.      * @return the undulation in m, positive means the geoid is higher than the
  201.      * ellipsoid.
  202.      * @see Geoid
  203.      * @see <a href="http://en.wikipedia.org/wiki/Geoid">Geoid on Wikipedia</a>
  204.      */
  205.     public double getUndulation(final double geodeticLatitude,
  206.                                 final double longitude,
  207.                                 final AbsoluteDate date) {
  208.         /*
  209.          * equations references are to the algorithm printed in the geoid
  210.          * cookbook[2]. See comment for Geoid.
  211.          */
  212.         // reference ellipsoid
  213.         final ReferenceEllipsoid ellipsoid = this.getEllipsoid();

  214.         // position in geodetic coordinates
  215.         final GeodeticPoint gp = new GeodeticPoint(geodeticLatitude, longitude, 0);
  216.         // position in Cartesian coordinates, is converted to geocentric lat and
  217.         // lon in the Holmes and Featherstone class
  218.         final Vector3D position = ellipsoid.transform(gp);

  219.         // get normal gravity from ellipsoid, eq 15
  220.         final double normalGravity = ellipsoid
  221.                 .getNormalGravity(geodeticLatitude);

  222.         // calculate disturbing potential, T, eq 30.
  223.         final double mu = this.harmonics.getMu();
  224.         final double T  = this.harmonics.nonCentralPart(date, position, mu);
  225.         // calculate undulation, eq 30
  226.         return T / normalGravity;
  227.     }

  228.     @Override
  229.     public ReferenceEllipsoid getEllipsoid() {
  230.         return this.referenceEllipsoid;
  231.     }

  232.     /**
  233.      * This class implements equations 20-24 in the geoid cook book.(Losch and
  234.      * Seufer) It modifies C<sub>2n,0</sub> where n = 1,2,...,5.
  235.      *
  236.      * @see "DMA TR 8350.2. 1984."
  237.      */
  238.     private static final class SubtractEllipsoid implements
  239.             NormalizedSphericalHarmonicsProvider {
  240.         /**
  241.          * provider of the fully normalized coefficients, includes the reference
  242.          * ellipsoid.
  243.          */
  244.         private final NormalizedSphericalHarmonicsProvider provider;
  245.         /**
  246.          * the reference ellipsoid to subtract from {@link #provider}.
  247.          */
  248.         private final ReferenceEllipsoid ellipsoid;

  249.         /**
  250.          * @param provider  potential used for GM<sub>g</sub> and a<sub>g</sub>,
  251.          *                  and of course the coefficients Cnm, and Snm.
  252.          * @param ellipsoid Used to calculate the fully normalized
  253.          *                  J<sub>2n</sub>
  254.          */
  255.         private SubtractEllipsoid(
  256.                 final NormalizedSphericalHarmonicsProvider provider,
  257.                 final ReferenceEllipsoid ellipsoid) {
  258.             super();
  259.             this.provider = provider;
  260.             this.ellipsoid = ellipsoid;
  261.         }

  262.         @Override
  263.         public int getMaxDegree() {
  264.             return this.provider.getMaxDegree();
  265.         }

  266.         @Override
  267.         public int getMaxOrder() {
  268.             return this.provider.getMaxOrder();
  269.         }

  270.         @Override
  271.         public double getMu() {
  272.             return this.provider.getMu();
  273.         }

  274.         @Override
  275.         public double getAe() {
  276.             return this.provider.getAe();
  277.         }

  278.         @Override
  279.         public AbsoluteDate getReferenceDate() {
  280.             return this.provider.getReferenceDate();
  281.         }

  282.         @Override
  283.         public double getOffset(final AbsoluteDate date) {
  284.             return this.provider.getOffset(date);
  285.         }

  286.         @Override
  287.         public NormalizedSphericalHarmonics onDate(final AbsoluteDate date) {
  288.             return new NormalizedSphericalHarmonics() {

  289.                 /** the original harmonics */
  290.                 private final NormalizedSphericalHarmonics delegate = provider.onDate(date);

  291.                 @Override
  292.                 public double getNormalizedCnm(final int n, final int m) {
  293.                     return getCorrectedCnm(n, m, this.delegate.getNormalizedCnm(n, m));
  294.                 }

  295.                 @Override
  296.                 public double getNormalizedSnm(final int n, final int m) {
  297.                     return this.delegate.getNormalizedSnm(n, m);
  298.                 }

  299.                 @Override
  300.                 public AbsoluteDate getDate() {
  301.                     return date;
  302.                 }
  303.             };
  304.         }

  305.         /**
  306.          * Get the corrected Cnm for different GM or a values.
  307.          *
  308.          * @param n              degree
  309.          * @param m              order
  310.          * @param uncorrectedCnm uncorrected Cnm coefficient
  311.          * @return the corrected Cnm coefficient.
  312.          */
  313.         private double getCorrectedCnm(final int n,
  314.                                        final int m,
  315.                                        final double uncorrectedCnm) {
  316.             double Cnm = uncorrectedCnm;
  317.             // n = 2,4,6,8, or 10 and m = 0
  318.             if (m == 0 && n <= 10 && n % 2 == 0 && n > 0) {
  319.                 // correction factor for different GM and a, 1 if no difference
  320.                 final double gmRatio = this.ellipsoid.getGM() / this.getMu();
  321.                 final double aRatio = this.ellipsoid.getEquatorialRadius() /
  322.                         this.getAe();
  323.                 /*
  324.                  * eq 20 in the geoid cook book[2], with eq 3-61 in chapter 3 of
  325.                  * DMA TR 8350.2
  326.                  */
  327.                 // halfN = 1,2,3,4,5 for n = 2,4,6,8,10, respectively
  328.                 final int halfN = n / 2;
  329.                 Cnm = Cnm - gmRatio * FastMath.pow(aRatio, halfN) *
  330.                         this.ellipsoid.getC2n0(halfN);
  331.             }
  332.             // return is a modified Cnm
  333.             return Cnm;
  334.         }

  335.         @Override
  336.         public TideSystem getTideSystem() {
  337.             return this.provider.getTideSystem();
  338.         }

  339.     }

  340.     /**
  341.      * {@inheritDoc}
  342.      *
  343.      * <p> The intersection point is computed using a line search along the
  344.      * specified line. This is accurate when the geoid is slowly varying.
  345.      */
  346.     @Override
  347.     public GeodeticPoint getIntersectionPoint(final Line lineInFrame,
  348.                                               final Vector3D closeInFrame,
  349.                                               final Frame frame,
  350.                                               final AbsoluteDate date) {
  351.         /*
  352.          * It is assumed that the geoid is slowly varying over it's entire
  353.          * surface. Therefore there will one local intersection.
  354.          */
  355.         // transform to body frame
  356.         final Frame bodyFrame = this.getBodyFrame();
  357.         final Transform frameToBody = frame.getTransformTo(bodyFrame, date);
  358.         final Vector3D close = frameToBody.transformPosition(closeInFrame);
  359.         final Line lineInBodyFrame = frameToBody.transformLine(lineInFrame);

  360.         // set the line's direction so the solved for value is always positive
  361.         final Line line;
  362.         if (lineInBodyFrame.getAbscissa(close) < 0) {
  363.             line = lineInBodyFrame.revert();
  364.         } else {
  365.             line = lineInBodyFrame;
  366.         }

  367.         final ReferenceEllipsoid ellipsoid = this.getEllipsoid();
  368.         // calculate end points
  369.         // distance from line to center of earth, squared
  370.         final double d2 = line.pointAt(0.0).getNormSq();
  371.         // the minimum abscissa, squared
  372.         final double n = ellipsoid.getPolarRadius() + MIN_UNDULATION;
  373.         final double minAbscissa2 = n * n - d2;
  374.         // smaller end point of the interval = 0.0 or intersection with
  375.         // min_undulation sphere
  376.         final double lowPoint = FastMath.sqrt(FastMath.max(minAbscissa2, 0.0));
  377.         // the maximum abscissa, squared
  378.         final double x = ellipsoid.getEquatorialRadius() + MAX_UNDULATION;
  379.         final double maxAbscissa2 = x * x - d2;
  380.         // larger end point of the interval
  381.         final double highPoint = FastMath.sqrt(maxAbscissa2);

  382.         // line search function
  383.         final UnivariateFunction heightFunction = new UnivariateFunction() {
  384.             @Override
  385.             public double value(final double x) {
  386.                 try {
  387.                     final GeodeticPoint geodetic =
  388.                             transform(line.pointAt(x), bodyFrame, date);
  389.                     return geodetic.getAltitude();
  390.                 } catch (OrekitException e) {
  391.                     // due to frame transform -> re-throw
  392.                     throw new RuntimeException(e);
  393.                 }
  394.             }
  395.         };

  396.         // compute answer
  397.         if (maxAbscissa2 < 0) {
  398.             // ray does not pierce bounding sphere -> no possible intersection
  399.             return null;
  400.         }
  401.         // solve line search problem to find the intersection
  402.         final UnivariateSolver solver = new BracketingNthOrderBrentSolver();
  403.         try {
  404.             final double abscissa = solver.solve(MAX_EVALUATIONS, heightFunction, lowPoint, highPoint);
  405.             // return intersection point
  406.             return this.transform(line.pointAt(abscissa), bodyFrame, date);
  407.         } catch (MathRuntimeException e) {
  408.             // no intersection
  409.             return null;
  410.         }
  411.     }

  412.     @Override
  413.     public Vector3D projectToGround(final Vector3D point,
  414.                                     final AbsoluteDate date,
  415.                                     final Frame frame) {
  416.         final GeodeticPoint gp = this.transform(point, frame, date);
  417.         final GeodeticPoint gpZero =
  418.                 new GeodeticPoint(gp.getLatitude(), gp.getLongitude(), 0);
  419.         final Transform bodyToFrame = this.getBodyFrame().getTransformTo(frame, date);
  420.         return bodyToFrame.transformPosition(this.transform(gpZero));
  421.     }

  422.     /**
  423.      * {@inheritDoc}
  424.      *
  425.      * <p> The intersection point is computed using a line search along the
  426.      * specified line. This is accurate when the geoid is slowly varying.
  427.      */
  428.     @Override
  429.     public <T extends RealFieldElement<T>> FieldGeodeticPoint<T> getIntersectionPoint(final FieldLine<T> lineInFrame,
  430.                                                                                       final FieldVector3D<T> closeInFrame,
  431.                                                                                       final Frame frame,
  432.                                                                                       final FieldAbsoluteDate<T> date) {

  433.         final Field<T> field = date.getField();
  434.         /*
  435.          * It is assumed that the geoid is slowly varying over it's entire
  436.          * surface. Therefore there will one local intersection.
  437.          */
  438.         // transform to body frame
  439.         final Frame bodyFrame = this.getBodyFrame();
  440.         final FieldTransform<T> frameToBody = frame.getTransformTo(bodyFrame, date);
  441.         final FieldVector3D<T> close = frameToBody.transformPosition(closeInFrame);
  442.         final FieldLine<T> lineInBodyFrame = frameToBody.transformLine(lineInFrame);

  443.         // set the line's direction so the solved for value is always positive
  444.         final FieldLine<T> line;
  445.         if (lineInBodyFrame.getAbscissa(close).getReal() < 0) {
  446.             line = lineInBodyFrame.revert();
  447.         } else {
  448.             line = lineInBodyFrame;
  449.         }

  450.         final ReferenceEllipsoid ellipsoid = this.getEllipsoid();
  451.         // calculate end points
  452.         // distance from line to center of earth, squared
  453.         final T d2 = line.pointAt(0.0).getNormSq();
  454.         // the minimum abscissa, squared
  455.         final double n = ellipsoid.getPolarRadius() + MIN_UNDULATION;
  456.         final T minAbscissa2 = d2.negate().add(n * n);
  457.         // smaller end point of the interval = 0.0 or intersection with
  458.         // min_undulation sphere
  459.         final T lowPoint = minAbscissa2.getReal() < 0 ? field.getZero() : minAbscissa2.sqrt();
  460.         // the maximum abscissa, squared
  461.         final double x = ellipsoid.getEquatorialRadius() + MAX_UNDULATION;
  462.         final T maxAbscissa2 = d2.negate().add(x * x);
  463.         // larger end point of the interval
  464.         final T highPoint = maxAbscissa2.sqrt();

  465.         // line search function
  466.         final RealFieldUnivariateFunction<T> heightFunction = z -> {
  467.             try {
  468.                 final FieldGeodeticPoint<T> geodetic =
  469.                         transform(line.pointAt(z), bodyFrame, date);
  470.                 return geodetic.getAltitude();
  471.             } catch (OrekitException e) {
  472.                 // due to frame transform -> re-throw
  473.                 throw new RuntimeException(e);
  474.             }
  475.         };

  476.         // compute answer
  477.         if (maxAbscissa2.getReal() < 0) {
  478.             // ray does not pierce bounding sphere -> no possible intersection
  479.             return null;
  480.         }
  481.         // solve line search problem to find the intersection
  482.         final FieldBracketingNthOrderBrentSolver<T> solver =
  483.                         new FieldBracketingNthOrderBrentSolver<>(field.getZero().add(1.0e-14),
  484.                                                                  field.getZero().add(1.0e-6),
  485.                                                                  field.getZero().add(1.0e-15),
  486.                                                                  5);
  487.         try {
  488.             final T abscissa = solver.solve(MAX_EVALUATIONS, heightFunction, lowPoint, highPoint,
  489.                                             AllowedSolution.ANY_SIDE);
  490.             // return intersection point
  491.             return this.transform(line.pointAt(abscissa), bodyFrame, date);
  492.         } catch (MathRuntimeException e) {
  493.             // no intersection
  494.             return null;
  495.         }
  496.     }

  497.     @Override
  498.     public TimeStampedPVCoordinates projectToGround(
  499.             final TimeStampedPVCoordinates pv,
  500.             final Frame frame) {
  501.         throw new UnsupportedOperationException();
  502.     }

  503.     /**
  504.      * {@inheritDoc}
  505.      *
  506.      * @param date date of the conversion. Used for computing frame
  507.      *             transformations and for time dependent geopotential.
  508.      * @return The surface relative point at the same location. Altitude is
  509.      * orthometric height, that is height above the {@link Geoid}. Latitude and
  510.      * longitude are both geodetic and defined with respect to the {@link
  511.      * #getEllipsoid() reference ellipsoid}.
  512.      * @see #transform(GeodeticPoint)
  513.      * @see <a href="http://en.wikipedia.org/wiki/Orthometric_height">Orthometric_height</a>
  514.      */
  515.     @Override
  516.     public GeodeticPoint transform(final Vector3D point, final Frame frame,
  517.                                    final AbsoluteDate date) {
  518.         // convert using reference ellipsoid, altitude referenced to ellipsoid
  519.         final GeodeticPoint ellipsoidal = this.getEllipsoid().transform(
  520.                 point, frame, date);
  521.         // convert altitude to orthometric using the undulation.
  522.         final double undulation = this.getUndulation(ellipsoidal.getLatitude(),
  523.                 ellipsoidal.getLongitude(), date);
  524.         // add undulation to the altitude
  525.         return new GeodeticPoint(
  526.                 ellipsoidal.getLatitude(),
  527.                 ellipsoidal.getLongitude(),
  528.                 ellipsoidal.getAltitude() - undulation
  529.         );
  530.     }

  531.     /**
  532.      * {@inheritDoc}
  533.      *
  534.      * @param date date of the conversion. Used for computing frame
  535.      *             transformations and for time dependent geopotential.
  536.      * @return The surface relative point at the same location. Altitude is
  537.      * orthometric height, that is height above the {@link Geoid}. Latitude and
  538.      * longitude are both geodetic and defined with respect to the {@link
  539.      * #getEllipsoid() reference ellipsoid}.
  540.      * @see #transform(GeodeticPoint)
  541.      * @see <a href="http://en.wikipedia.org/wiki/Orthometric_height">Orthometric_height</a>
  542.      */
  543.     @Override
  544.     public <T extends RealFieldElement<T>> FieldGeodeticPoint<T> transform(final FieldVector3D<T> point, final Frame frame,
  545.                                                                            final FieldAbsoluteDate<T> date) {
  546.         // convert using reference ellipsoid, altitude referenced to ellipsoid
  547.         final FieldGeodeticPoint<T> ellipsoidal = this.getEllipsoid().transform(
  548.                 point, frame, date);
  549.         // convert altitude to orthometric using the undulation.
  550.         final double undulation = this.getUndulation(ellipsoidal.getLatitude().getReal(),
  551.                                                      ellipsoidal.getLongitude().getReal(),
  552.                                                      date.toAbsoluteDate());
  553.         // add undulation to the altitude
  554.         return new FieldGeodeticPoint<>(
  555.                 ellipsoidal.getLatitude(),
  556.                 ellipsoidal.getLongitude(),
  557.                 ellipsoidal.getAltitude().subtract(undulation)
  558.         );
  559.     }

  560.     /**
  561.      * {@inheritDoc}
  562.      *
  563.      * @param point The surface relative point to transform. Altitude is
  564.      *              orthometric height, that is height above the {@link Geoid}.
  565.      *              Latitude and longitude are both geodetic and defined with
  566.      *              respect to the {@link #getEllipsoid() reference ellipsoid}.
  567.      * @return point at the same location but as a Cartesian point in the {@link
  568.      * #getBodyFrame() body frame}.
  569.      * @see #transform(Vector3D, Frame, AbsoluteDate)
  570.      */
  571.     @Override
  572.     public Vector3D transform(final GeodeticPoint point) {
  573.         try {
  574.             // convert orthometric height to height above ellipsoid using undulation
  575.             // TODO pass in date to allow user to specify
  576.             final double undulation = this.getUndulation(
  577.                     point.getLatitude(),
  578.                     point.getLongitude(),
  579.                     this.defaultDate
  580.             );
  581.             final GeodeticPoint ellipsoidal = new GeodeticPoint(
  582.                     point.getLatitude(),
  583.                     point.getLongitude(),
  584.                     point.getAltitude() + undulation
  585.             );
  586.             // transform using reference ellipsoid
  587.             return this.getEllipsoid().transform(ellipsoidal);
  588.         } catch (OrekitException e) {
  589.             //this method, as defined in BodyShape, is not permitted to throw
  590.             //an OrekitException, so wrap in an exception we can throw.
  591.             throw new RuntimeException(e);
  592.         }
  593.     }

  594.     /**
  595.      * {@inheritDoc}
  596.      *
  597.      * @param point The surface relative point to transform. Altitude is
  598.      *              orthometric height, that is height above the {@link Geoid}.
  599.      *              Latitude and longitude are both geodetic and defined with
  600.      *              respect to the {@link #getEllipsoid() reference ellipsoid}.
  601.      * @param <T> type of the field elements
  602.      * @return point at the same location but as a Cartesian point in the {@link
  603.      * #getBodyFrame() body frame}.
  604.      * @see #transform(Vector3D, Frame, AbsoluteDate)
  605.      * @since 9.0
  606.      */
  607.     @Override
  608.     public <T extends RealFieldElement<T>> FieldVector3D<T> transform(final FieldGeodeticPoint<T> point) {
  609.         try {
  610.             // convert orthometric height to height above ellipsoid using undulation
  611.             // TODO pass in date to allow user to specify
  612.             final double undulation = this.getUndulation(
  613.                     point.getLatitude().getReal(),
  614.                     point.getLongitude().getReal(),
  615.                     this.defaultDate
  616.             );
  617.             final FieldGeodeticPoint<T> ellipsoidal = new FieldGeodeticPoint<>(
  618.                     point.getLatitude(),
  619.                     point.getLongitude(),
  620.                     point.getAltitude().add(undulation)
  621.             );
  622.             // transform using reference ellipsoid
  623.             return this.getEllipsoid().transform(ellipsoidal);
  624.         } catch (OrekitException e) {
  625.             //this method, as defined in BodyShape, is not permitted to throw
  626.             //an OrekitException, so wrap in an exception we can throw.
  627.             throw new RuntimeException(e);
  628.         }
  629.     }

  630. }