1   /* Contributed in the public domain.
2    * Licensed to CS GROUP (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  
19  import org.hipparchus.Field;
20  import org.hipparchus.CalculusFieldElement;
21  import org.hipparchus.analysis.CalculusFieldUnivariateFunction;
22  import org.hipparchus.analysis.UnivariateFunction;
23  import org.hipparchus.analysis.solvers.AllowedSolution;
24  import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
25  import org.hipparchus.analysis.solvers.FieldBracketingNthOrderBrentSolver;
26  import org.hipparchus.analysis.solvers.UnivariateSolver;
27  import org.hipparchus.exception.MathRuntimeException;
28  import org.hipparchus.geometry.euclidean.threed.FieldLine;
29  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
30  import org.hipparchus.geometry.euclidean.threed.Line;
31  import org.hipparchus.geometry.euclidean.threed.Vector3D;
32  import org.hipparchus.util.FastMath;
33  import org.orekit.bodies.FieldGeodeticPoint;
34  import org.orekit.bodies.GeodeticPoint;
35  import org.orekit.errors.OrekitException;
36  import org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel;
37  import org.orekit.forces.gravity.potential.GravityFields;
38  import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider;
39  import org.orekit.forces.gravity.potential.TideSystem;
40  import org.orekit.frames.FieldTransform;
41  import org.orekit.frames.Frame;
42  import org.orekit.frames.StaticTransform;
43  import org.orekit.time.AbsoluteDate;
44  import org.orekit.time.FieldAbsoluteDate;
45  import org.orekit.utils.TimeStampedPVCoordinates;
46  
47  /**
48   * A geoid is a level surface of the gravity potential of a body. The gravity
49   * potential, W, is split so W = U + T, where U is the normal potential (defined
50   * by the ellipsoid) and T is the anomalous potential.[3](eq. 2-137)
51   *
52   * <p> The {@link #getIntersectionPoint(Line, Vector3D, Frame, AbsoluteDate)}
53   * method is tailored specifically for Earth's geoid. All of the other methods
54   * in this class are general and will work for an arbitrary body.
55   *
56   * <p> There are several components that are needed to define a geoid[1]:
57   *
58   * <ul> <li>Geopotential field. These are the coefficients of the spherical
59   * harmonics: S<sub>n,m</sub> and C<sub>n,m</sub></li>
60   *
61   * <li>Reference Ellipsoid. The ellipsoid is used to define the undulation of
62   * the geoid (distance between ellipsoid and geoid) and U<sub>0</sub> the value
63   * of the normal gravity potential at the surface of the ellipsoid.</li>
64   *
65   * <li>W<sub>0</sub>, the potential at the geoid. The value of the potential on
66   * the level surface. This is taken to be U<sub>0</sub>, the normal gravity
67   * potential at the surface of the {@link ReferenceEllipsoid}.</li>
68   *
69   * <li>Permanent Tide System. This implementation assumes that the geopotential
70   * field and the reference ellipsoid use the same permanent tide system. If the
71   * assumption is false it will produce errors of about 0.5 m. Conversion between
72   * tide systems is a possible improvement.[1,2]</li>
73   *
74   * <li>Topographic Masses. That is mass outside of the geoid, e.g. mountains.
75   * This implementation ignores topographic masses, which causes up to 3m error
76   * in the Himalayas, and ~ 1.5m error in the Rockies. This could be improved
77   * through the use of DTED and calculating height anomalies or using the
78   * correction coefficients.[1]</li> </ul>
79   *
80   * <p> This implementation also assumes that the normal to the reference
81   * ellipsoid is the same as the normal to the geoid. This assumption enables the
82   * equation: (height above geoid) = (height above ellipsoid) - (undulation),
83   * which is used in {@link #transform(GeodeticPoint)} and {@link
84   * #transform(Vector3D, Frame, AbsoluteDate)}.
85   *
86   * <p> In testing, the error in the undulations calculated by this class were
87   * off by less than 3 meters, which matches the assumptions outlined above.
88   *
89   * <p> References:
90   *
91   * <ol> <li>Dru A. Smith. There is no such thing as "The" EGM96 geoid: Subtle
92   * points on the use of a global geopotential model. IGeS Bulletin No. 8:17-28,
93   * 1998. <a href= "http://www.ngs.noaa.gov/PUBS_LIB/EGM96_GEOID_PAPER/egm96_geoid_paper.html"
94   * >http://www.ngs.noaa.gov/PUBS_LIB/EGM96_GEOID_PAPER/egm96_geoid_paper.html</a></li>
95   *
96   * <li> Martin Losch, Verena Seufer. How to Compute Geoid Undulations (Geoid
97   * Height Relative to a Given Reference Ellipsoid) from Spherical Harmonic
98   * Coefficients for Satellite Altimetry Applications. , 2003. <a
99   * href="http://mitgcm.org/~mlosch/geoidcookbook.pdf">mitgcm.org/~mlosch/geoidcookbook.pdf</a>
100  * </li>
101  *
102  * <li>Weikko A. Heiskanen, Helmut Moritz. Physical Geodesy. W. H. Freeman and
103  * Company, 1967. (especially sections 2.13 and equation 2-144 Bruns
104  * Formula)</li>
105  *
106  * <li>S. A. Holmes, W. E. Featherstone. A unified approach to the Clenshaw
107  * summation and the recursive computation of very high degree and order
108  * normalised associated Legendre functions. Journal of Geodesy, 76(5):279,
109  * 2002.</li>
110  *
111  * <li>DMA TR 8350.2. 1984.</li>
112  *
113  * <li>Department of Defense World Geodetic System 1984. 2000. NIMA TR 8350.2
114  * Third Edition, Amendment 1.</li> </ol>
115  *
116  * @author Evan Ward
117  */
118 public class Geoid implements EarthShape {
119 
120     /**
121      * uid is date of last modification.
122      */
123     private static final long serialVersionUID = 20150312L;
124 
125     /**
126      * A number larger than the largest undulation. Wikipedia says the geoid
127      * height is in [-106, 85]. I chose 100 to be safe.
128      */
129     private static final double MAX_UNDULATION = 100;
130     /**
131      * A number smaller than the smallest undulation. Wikipedia says the geoid
132      * height is in [-106, 85]. I chose -150 to be safe.
133      */
134     private static final double MIN_UNDULATION = -150;
135     /**
136      * the maximum number of evaluations for the line search in {@link
137      * #getIntersectionPoint(Line, Vector3D, Frame, AbsoluteDate)}.
138      */
139     private static final int MAX_EVALUATIONS = 100;
140 
141     /**
142      * the default date to use when evaluating the {@link #harmonics}. Used when
143      * no other dates are available. Should be removed in a future release.
144      */
145     private final AbsoluteDate defaultDate;
146     /**
147      * the reference ellipsoid.
148      */
149     private final ReferenceEllipsoid referenceEllipsoid;
150     /**
151      * the geo-potential combined with an algorithm for evaluating the spherical
152      * harmonics. The Holmes and Featherstone method is very robust.
153      */
154     private final transient HolmesFeatherstoneAttractionModel harmonics;
155 
156     /**
157      * Creates a geoid from the given geopotential, reference ellipsoid and the
158      * assumptions in the comment for {@link Geoid}.
159      *
160      * @param geopotential       the gravity potential. Only the anomalous
161      *                           potential will be used. It is assumed that the
162      *                           {@code geopotential} and the {@code
163      *                           referenceEllipsoid} are defined in the same
164      *                           frame. Usually a {@link GravityFields#getConstantNormalizedProvider(int,
165      *                           int) constant geopotential} is used to define a
166      *                           time-invariant Geoid.
167      * @param referenceEllipsoid the normal gravity potential.
168      * @throws NullPointerException if {@code geopotential == null ||
169      *                              referenceEllipsoid == null}
170      */
171     public Geoid(final NormalizedSphericalHarmonicsProvider geopotential,
172                  final ReferenceEllipsoid referenceEllipsoid) {
173         // parameter check
174         if (geopotential == null || referenceEllipsoid == null) {
175             throw new NullPointerException();
176         }
177 
178         // subtract the ellipsoid from the geopotential
179         final SubtractEllipsoid potential = new SubtractEllipsoid(geopotential,
180                 referenceEllipsoid);
181 
182         // set instance parameters
183         this.referenceEllipsoid = referenceEllipsoid;
184         this.harmonics = new HolmesFeatherstoneAttractionModel(
185                 referenceEllipsoid.getBodyFrame(), potential);
186         this.defaultDate = AbsoluteDate.ARBITRARY_EPOCH;
187     }
188 
189     @Override
190     public Frame getBodyFrame() {
191         // same as for reference ellipsoid.
192         return this.getEllipsoid().getBodyFrame();
193     }
194 
195     /**
196      * Gets the Undulation of the Geoid, N at the given position. N is the
197      * distance between the {@link #getEllipsoid() reference ellipsoid} and the
198      * geoid. The latitude and longitude parameters are both defined with
199      * respect to the reference ellipsoid. For EGM96 and the WGS84 ellipsoid the
200      * undulation is between -107m and +86m.
201      *
202      * <p> NOTE: Restrictions are not put on the range of the arguments {@code
203      * geodeticLatitude} and {@code longitude}.
204      *
205      * @param geodeticLatitude geodetic latitude (angle between the local normal
206      *                         and the equatorial plane on the reference
207      *                         ellipsoid), in radians.
208      * @param longitude        on the reference ellipsoid, in radians.
209      * @param date             of evaluation. Used for time varying geopotential
210      *                         fields.
211      * @return the undulation in m, positive means the geoid is higher than the
212      * ellipsoid.
213      * @see Geoid
214      * @see <a href="http://en.wikipedia.org/wiki/Geoid">Geoid on Wikipedia</a>
215      */
216     public double getUndulation(final double geodeticLatitude,
217                                 final double longitude,
218                                 final AbsoluteDate date) {
219         /*
220          * equations references are to the algorithm printed in the geoid
221          * cookbook[2]. See comment for Geoid.
222          */
223         // reference ellipsoid
224         final ReferenceEllipsoid ellipsoid = this.getEllipsoid();
225 
226         // position in geodetic coordinates
227         final GeodeticPoint gp = new GeodeticPoint(geodeticLatitude, longitude, 0);
228         // position in Cartesian coordinates, is converted to geocentric lat and
229         // lon in the Holmes and Featherstone class
230         final Vector3D position = ellipsoid.transform(gp);
231 
232         // get normal gravity from ellipsoid, eq 15
233         final double normalGravity = ellipsoid
234                 .getNormalGravity(geodeticLatitude);
235 
236         // calculate disturbing potential, T, eq 30.
237         final double mu = this.harmonics.getMu();
238         final double T  = this.harmonics.nonCentralPart(date, position, mu);
239         // calculate undulation, eq 30
240         return T / normalGravity;
241     }
242 
243     @Override
244     public ReferenceEllipsoid getEllipsoid() {
245         return this.referenceEllipsoid;
246     }
247 
248     /**
249      * This class implements equations 20-24 in the geoid cook book.(Losch and
250      * Seufer) It modifies C<sub>2n,0</sub> where n = 1,2,...,5.
251      *
252      * @see "DMA TR 8350.2. 1984."
253      */
254     private static final class SubtractEllipsoid implements
255             NormalizedSphericalHarmonicsProvider {
256         /**
257          * provider of the fully normalized coefficients, includes the reference
258          * ellipsoid.
259          */
260         private final NormalizedSphericalHarmonicsProvider provider;
261         /**
262          * the reference ellipsoid to subtract from {@link #provider}.
263          */
264         private final ReferenceEllipsoid ellipsoid;
265 
266         /**
267          * @param provider  potential used for GM<sub>g</sub> and a<sub>g</sub>,
268          *                  and of course the coefficients Cnm, and Snm.
269          * @param ellipsoid Used to calculate the fully normalized
270          *                  J<sub>2n</sub>
271          */
272         private SubtractEllipsoid(
273                 final NormalizedSphericalHarmonicsProvider provider,
274                 final ReferenceEllipsoid ellipsoid) {
275             super();
276             this.provider = provider;
277             this.ellipsoid = ellipsoid;
278         }
279 
280         @Override
281         public int getMaxDegree() {
282             return this.provider.getMaxDegree();
283         }
284 
285         @Override
286         public int getMaxOrder() {
287             return this.provider.getMaxOrder();
288         }
289 
290         @Override
291         public double getMu() {
292             return this.provider.getMu();
293         }
294 
295         @Override
296         public double getAe() {
297             return this.provider.getAe();
298         }
299 
300         @Override
301         public AbsoluteDate getReferenceDate() {
302             return this.provider.getReferenceDate();
303         }
304 
305         @Deprecated
306         @Override
307         public double getOffset(final AbsoluteDate date) {
308             return this.provider.getOffset(date);
309         }
310 
311         @Override
312         public NormalizedSphericalHarmonics onDate(final AbsoluteDate date) {
313             return new NormalizedSphericalHarmonics() {
314 
315                 /** the original harmonics */
316                 private final NormalizedSphericalHarmonics delegate = provider.onDate(date);
317 
318                 @Override
319                 public double getNormalizedCnm(final int n, final int m) {
320                     return getCorrectedCnm(n, m, this.delegate.getNormalizedCnm(n, m));
321                 }
322 
323                 @Override
324                 public double getNormalizedSnm(final int n, final int m) {
325                     return this.delegate.getNormalizedSnm(n, m);
326                 }
327 
328                 @Override
329                 public AbsoluteDate getDate() {
330                     return date;
331                 }
332             };
333         }
334 
335         /**
336          * Get the corrected Cnm for different GM or a values.
337          *
338          * @param n              degree
339          * @param m              order
340          * @param uncorrectedCnm uncorrected Cnm coefficient
341          * @return the corrected Cnm coefficient.
342          */
343         private double getCorrectedCnm(final int n,
344                                        final int m,
345                                        final double uncorrectedCnm) {
346             double Cnm = uncorrectedCnm;
347             // n = 2,4,6,8, or 10 and m = 0
348             if (m == 0 && n <= 10 && n % 2 == 0 && n > 0) {
349                 // correction factor for different GM and a, 1 if no difference
350                 final double gmRatio = this.ellipsoid.getGM() / this.getMu();
351                 final double aRatio = this.ellipsoid.getEquatorialRadius() /
352                         this.getAe();
353                 /*
354                  * eq 20 in the geoid cook book[2], with eq 3-61 in chapter 3 of
355                  * DMA TR 8350.2
356                  */
357                 // halfN = 1,2,3,4,5 for n = 2,4,6,8,10, respectively
358                 final int halfN = n / 2;
359                 Cnm = Cnm - gmRatio * FastMath.pow(aRatio, halfN) *
360                         this.ellipsoid.getC2n0(halfN);
361             }
362             // return is a modified Cnm
363             return Cnm;
364         }
365 
366         @Override
367         public TideSystem getTideSystem() {
368             return this.provider.getTideSystem();
369         }
370 
371     }
372 
373     /**
374      * {@inheritDoc}
375      *
376      * <p> The intersection point is computed using a line search along the
377      * specified line. This is accurate when the geoid is slowly varying.
378      */
379     @Override
380     public GeodeticPoint getIntersectionPoint(final Line lineInFrame,
381                                               final Vector3D closeInFrame,
382                                               final Frame frame,
383                                               final AbsoluteDate date) {
384         /*
385          * It is assumed that the geoid is slowly varying over it's entire
386          * surface. Therefore there will one local intersection.
387          */
388         // transform to body frame
389         final Frame bodyFrame = this.getBodyFrame();
390         final StaticTransform frameToBody =
391                 frame.getStaticTransformTo(bodyFrame, date);
392         final Vector3D close = frameToBody.transformPosition(closeInFrame);
393         final Line lineInBodyFrame = frameToBody.transformLine(lineInFrame);
394 
395         // set the line's direction so the solved for value is always positive
396         final Line line;
397         if (lineInBodyFrame.getAbscissa(close) < 0) {
398             line = lineInBodyFrame.revert();
399         } else {
400             line = lineInBodyFrame;
401         }
402 
403         final ReferenceEllipsoid ellipsoid = this.getEllipsoid();
404         // calculate end points
405         // distance from line to center of earth, squared
406         final double d2 = line.pointAt(0.0).getNormSq();
407         // the minimum abscissa, squared
408         final double n = ellipsoid.getPolarRadius() + MIN_UNDULATION;
409         final double minAbscissa2 = n * n - d2;
410         // smaller end point of the interval = 0.0 or intersection with
411         // min_undulation sphere
412         final double lowPoint = FastMath.sqrt(FastMath.max(minAbscissa2, 0.0));
413         // the maximum abscissa, squared
414         final double x = ellipsoid.getEquatorialRadius() + MAX_UNDULATION;
415         final double maxAbscissa2 = x * x - d2;
416         // larger end point of the interval
417         final double highPoint = FastMath.sqrt(maxAbscissa2);
418 
419         // line search function
420         final UnivariateFunction heightFunction = new UnivariateFunction() {
421             @Override
422             public double value(final double x) {
423                 try {
424                     final GeodeticPoint geodetic =
425                             transform(line.pointAt(x), bodyFrame, date);
426                     return geodetic.getAltitude();
427                 } catch (OrekitException e) {
428                     // due to frame transform -> re-throw
429                     throw new RuntimeException(e);
430                 }
431             }
432         };
433 
434         // compute answer
435         if (maxAbscissa2 < 0) {
436             // ray does not pierce bounding sphere -> no possible intersection
437             return null;
438         }
439         // solve line search problem to find the intersection
440         final UnivariateSolver solver = new BracketingNthOrderBrentSolver();
441         try {
442             final double abscissa = solver.solve(MAX_EVALUATIONS, heightFunction, lowPoint, highPoint);
443             // return intersection point
444             return this.transform(line.pointAt(abscissa), bodyFrame, date);
445         } catch (MathRuntimeException e) {
446             // no intersection
447             return null;
448         }
449     }
450 
451     @Override
452     public Vector3D projectToGround(final Vector3D point,
453                                     final AbsoluteDate date,
454                                     final Frame frame) {
455         final GeodeticPoint gp = this.transform(point, frame, date);
456         final GeodeticPoint gpZero =
457                 new GeodeticPoint(gp.getLatitude(), gp.getLongitude(), 0);
458         final StaticTransform bodyToFrame =
459                 this.getBodyFrame().getStaticTransformTo(frame, date);
460         return bodyToFrame.transformPosition(this.transform(gpZero));
461     }
462 
463     /**
464      * {@inheritDoc}
465      *
466      * <p> The intersection point is computed using a line search along the
467      * specified line. This is accurate when the geoid is slowly varying.
468      */
469     @Override
470     public <T extends CalculusFieldElement<T>> FieldGeodeticPoint<T> getIntersectionPoint(final FieldLine<T> lineInFrame,
471                                                                                       final FieldVector3D<T> closeInFrame,
472                                                                                       final Frame frame,
473                                                                                       final FieldAbsoluteDate<T> date) {
474 
475         final Field<T> field = date.getField();
476         /*
477          * It is assumed that the geoid is slowly varying over it's entire
478          * surface. Therefore there will one local intersection.
479          */
480         // transform to body frame
481         final Frame bodyFrame = this.getBodyFrame();
482         final FieldTransform<T> frameToBody = frame.getTransformTo(bodyFrame, date);
483         final FieldVector3D<T> close = frameToBody.transformPosition(closeInFrame);
484         final FieldLine<T> lineInBodyFrame = frameToBody.transformLine(lineInFrame);
485 
486         // set the line's direction so the solved for value is always positive
487         final FieldLine<T> line;
488         if (lineInBodyFrame.getAbscissa(close).getReal() < 0) {
489             line = lineInBodyFrame.revert();
490         } else {
491             line = lineInBodyFrame;
492         }
493 
494         final ReferenceEllipsoid ellipsoid = this.getEllipsoid();
495         // calculate end points
496         // distance from line to center of earth, squared
497         final T d2 = line.pointAt(0.0).getNormSq();
498         // the minimum abscissa, squared
499         final double n = ellipsoid.getPolarRadius() + MIN_UNDULATION;
500         final T minAbscissa2 = d2.negate().add(n * n);
501         // smaller end point of the interval = 0.0 or intersection with
502         // min_undulation sphere
503         final T lowPoint = minAbscissa2.getReal() < 0 ? field.getZero() : minAbscissa2.sqrt();
504         // the maximum abscissa, squared
505         final double x = ellipsoid.getEquatorialRadius() + MAX_UNDULATION;
506         final T maxAbscissa2 = d2.negate().add(x * x);
507         // larger end point of the interval
508         final T highPoint = maxAbscissa2.sqrt();
509 
510         // line search function
511         final CalculusFieldUnivariateFunction<T> heightFunction = z -> {
512             try {
513                 final FieldGeodeticPoint<T> geodetic =
514                         transform(line.pointAt(z), bodyFrame, date);
515                 return geodetic.getAltitude();
516             } catch (OrekitException e) {
517                 // due to frame transform -> re-throw
518                 throw new RuntimeException(e);
519             }
520         };
521 
522         // compute answer
523         if (maxAbscissa2.getReal() < 0) {
524             // ray does not pierce bounding sphere -> no possible intersection
525             return null;
526         }
527         // solve line search problem to find the intersection
528         final FieldBracketingNthOrderBrentSolver<T> solver =
529                         new FieldBracketingNthOrderBrentSolver<>(field.getZero().add(1.0e-14),
530                                                                  field.getZero().add(1.0e-6),
531                                                                  field.getZero().add(1.0e-15),
532                                                                  5);
533         try {
534             final T abscissa = solver.solve(MAX_EVALUATIONS, heightFunction, lowPoint, highPoint,
535                                             AllowedSolution.ANY_SIDE);
536             // return intersection point
537             return this.transform(line.pointAt(abscissa), bodyFrame, date);
538         } catch (MathRuntimeException e) {
539             // no intersection
540             return null;
541         }
542     }
543 
544     @Override
545     public TimeStampedPVCoordinates projectToGround(
546             final TimeStampedPVCoordinates pv,
547             final Frame frame) {
548         throw new UnsupportedOperationException();
549     }
550 
551     /**
552      * {@inheritDoc}
553      *
554      * @param date date of the conversion. Used for computing frame
555      *             transformations and for time dependent geopotential.
556      * @return The surface relative point at the same location. Altitude is
557      * orthometric height, that is height above the {@link Geoid}. Latitude and
558      * longitude are both geodetic and defined with respect to the {@link
559      * #getEllipsoid() reference ellipsoid}.
560      * @see #transform(GeodeticPoint)
561      * @see <a href="http://en.wikipedia.org/wiki/Orthometric_height">Orthometric_height</a>
562      */
563     @Override
564     public GeodeticPoint transform(final Vector3D point, final Frame frame,
565                                    final AbsoluteDate date) {
566         // convert using reference ellipsoid, altitude referenced to ellipsoid
567         final GeodeticPoint ellipsoidal = this.getEllipsoid().transform(
568                 point, frame, date);
569         // convert altitude to orthometric using the undulation.
570         final double undulation = this.getUndulation(ellipsoidal.getLatitude(),
571                 ellipsoidal.getLongitude(), date);
572         // add undulation to the altitude
573         return new GeodeticPoint(
574                 ellipsoidal.getLatitude(),
575                 ellipsoidal.getLongitude(),
576                 ellipsoidal.getAltitude() - undulation
577         );
578     }
579 
580     /**
581      * {@inheritDoc}
582      *
583      * @param date date of the conversion. Used for computing frame
584      *             transformations and for time dependent geopotential.
585      * @return The surface relative point at the same location. Altitude is
586      * orthometric height, that is height above the {@link Geoid}. Latitude and
587      * longitude are both geodetic and defined with respect to the {@link
588      * #getEllipsoid() reference ellipsoid}.
589      * @see #transform(GeodeticPoint)
590      * @see <a href="http://en.wikipedia.org/wiki/Orthometric_height">Orthometric_height</a>
591      */
592     @Override
593     public <T extends CalculusFieldElement<T>> FieldGeodeticPoint<T> transform(final FieldVector3D<T> point, final Frame frame,
594                                                                            final FieldAbsoluteDate<T> date) {
595         // convert using reference ellipsoid, altitude referenced to ellipsoid
596         final FieldGeodeticPoint<T> ellipsoidal = this.getEllipsoid().transform(
597                 point, frame, date);
598         // convert altitude to orthometric using the undulation.
599         final double undulation = this.getUndulation(ellipsoidal.getLatitude().getReal(),
600                                                      ellipsoidal.getLongitude().getReal(),
601                                                      date.toAbsoluteDate());
602         // add undulation to the altitude
603         return new FieldGeodeticPoint<>(
604                 ellipsoidal.getLatitude(),
605                 ellipsoidal.getLongitude(),
606                 ellipsoidal.getAltitude().subtract(undulation)
607         );
608     }
609 
610     /**
611      * {@inheritDoc}
612      *
613      * @param point The surface relative point to transform. Altitude is
614      *              orthometric height, that is height above the {@link Geoid}.
615      *              Latitude and longitude are both geodetic and defined with
616      *              respect to the {@link #getEllipsoid() reference ellipsoid}.
617      * @return point at the same location but as a Cartesian point in the {@link
618      * #getBodyFrame() body frame}.
619      * @see #transform(Vector3D, Frame, AbsoluteDate)
620      */
621     @Override
622     public Vector3D transform(final GeodeticPoint point) {
623         try {
624             // convert orthometric height to height above ellipsoid using undulation
625             // TODO pass in date to allow user to specify
626             final double undulation = this.getUndulation(
627                     point.getLatitude(),
628                     point.getLongitude(),
629                     this.defaultDate
630             );
631             final GeodeticPoint ellipsoidal = new GeodeticPoint(
632                     point.getLatitude(),
633                     point.getLongitude(),
634                     point.getAltitude() + undulation
635             );
636             // transform using reference ellipsoid
637             return this.getEllipsoid().transform(ellipsoidal);
638         } catch (OrekitException e) {
639             //this method, as defined in BodyShape, is not permitted to throw
640             //an OrekitException, so wrap in an exception we can throw.
641             throw new RuntimeException(e);
642         }
643     }
644 
645     /**
646      * {@inheritDoc}
647      *
648      * @param point The surface relative point to transform. Altitude is
649      *              orthometric height, that is height above the {@link Geoid}.
650      *              Latitude and longitude are both geodetic and defined with
651      *              respect to the {@link #getEllipsoid() reference ellipsoid}.
652      * @param <T> type of the field elements
653      * @return point at the same location but as a Cartesian point in the {@link
654      * #getBodyFrame() body frame}.
655      * @see #transform(Vector3D, Frame, AbsoluteDate)
656      * @since 9.0
657      */
658     @Override
659     public <T extends CalculusFieldElement<T>> FieldVector3D<T> transform(final FieldGeodeticPoint<T> point) {
660         try {
661             // convert orthometric height to height above ellipsoid using undulation
662             // TODO pass in date to allow user to specify
663             final double undulation = this.getUndulation(
664                     point.getLatitude().getReal(),
665                     point.getLongitude().getReal(),
666                     this.defaultDate
667             );
668             final FieldGeodeticPoint<T> ellipsoidal = new FieldGeodeticPoint<>(
669                     point.getLatitude(),
670                     point.getLongitude(),
671                     point.getAltitude().add(undulation)
672             );
673             // transform using reference ellipsoid
674             return this.getEllipsoid().transform(ellipsoidal);
675         } catch (OrekitException e) {
676             //this method, as defined in BodyShape, is not permitted to throw
677             //an OrekitException, so wrap in an exception we can throw.
678             throw new RuntimeException(e);
679         }
680     }
681 
682 }