1   /* Copyright 2013-2025 CS GROUP
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.rugged.intersection;
18  
19  import org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.orekit.bodies.GeodeticPoint;
21  import org.orekit.rugged.api.AlgorithmId;
22  import org.orekit.rugged.errors.DumpManager;
23  import org.orekit.rugged.utils.ExtendedEllipsoid;
24  import org.orekit.rugged.utils.NormalizedGeodeticPoint;
25  
26  /** Intersection ignoring Digital Elevation Model.
27   * <p>
28   * This implementation uses a constant elevation over the ellipsoid.
29   * </p>
30   * @author Luc Maisonobe
31   * @author Guylaine Prat
32   */
33  public class ConstantElevationAlgorithm implements IntersectionAlgorithm {
34  
35      /** Constant elevation over ellipsoid. */
36      private final double constantElevation;
37  
38      /** Algorithm Id.
39       * @since 2.2 */
40      private final AlgorithmId algorithmId;
41  
42      /** Simple constructor.
43       * @param constantElevation constant elevation over ellipsoid
44       */
45      public ConstantElevationAlgorithm(final double constantElevation) {
46          this.constantElevation = constantElevation;
47          this.algorithmId = AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID;
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public NormalizedGeodeticPoint intersection(final ExtendedEllipsoid ellipsoid,
53                                                  final Vector3D position, final Vector3D los) {
54          DumpManager.dumpAlgorithm(this.algorithmId, constantElevation);
55          final Vector3D      p  = ellipsoid.pointAtAltitude(position, los, constantElevation);
56          final GeodeticPoint gp = ellipsoid.transform(p, ellipsoid.getFrame(), null);
57          return new NormalizedGeodeticPoint(gp.getLatitude(), gp.getLongitude(), gp.getAltitude(), 0.0);
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public NormalizedGeodeticPoint refineIntersection(final ExtendedEllipsoid ellipsoid,
63                                                        final Vector3D position, final Vector3D los,
64                                                        final NormalizedGeodeticPoint closeGuess) {
65          DumpManager.dumpAlgorithm(this.algorithmId, constantElevation);
66          final Vector3D      p  = ellipsoid.pointAtAltitude(position, los, constantElevation);
67          final GeodeticPoint gp = ellipsoid.transform(p, ellipsoid.getFrame(), null);
68          return new NormalizedGeodeticPoint(gp.getLatitude(), gp.getLongitude(), gp.getAltitude(),
69                  closeGuess.getLongitude());
70      }
71  
72      /** {@inheritDoc}
73       * <p>
74       * As this algorithm uses a constant elevation,
75       * this method always returns the same value.
76       * </p>
77       */
78      @Override
79      public double getElevation(final double latitude, final double longitude) {
80          DumpManager.dumpAlgorithm(this.algorithmId, constantElevation);
81          return constantElevation;
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public AlgorithmId getAlgorithmId() {
87          return this.algorithmId;
88      }
89  }