1   /* Copyright 2002-2022 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.bodies;
18  
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.hipparchus.geometry.euclidean.threed.Vector3D;
24  import org.hipparchus.geometry.euclidean.twod.Vector2D;
25  import org.hipparchus.util.FastMath;
26  import org.junit.Assert;
27  import org.junit.Before;
28  import org.junit.Test;
29  import org.orekit.Utils;
30  import org.orekit.frames.FramesFactory;
31  import org.orekit.time.AbsoluteDate;
32  import org.orekit.utils.CartesianDerivativesFilter;
33  import org.orekit.utils.Constants;
34  import org.orekit.utils.IERSConventions;
35  import org.orekit.utils.TimeStampedPVCoordinates;
36  
37  
38  public class EllipseTest {
39  
40      @Test
41      public void testMeridianShape() {
42          OneAxisEllipsoid model =
43                  new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
44                                       Constants.WGS84_EARTH_FLATTENING,
45                                       FramesFactory.getITRF(IERSConventions.IERS_2010, true));
46          Ellipse e = model.getPlaneSection(new Vector3D(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, 0, 0),
47                                            Vector3D.PLUS_J);
48          Assert.assertEquals(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
49                              e.getA(),
50                              1.0e-15 * Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
51          Assert.assertEquals(Constants.WGS84_EARTH_EQUATORIAL_RADIUS * (1 - Constants.WGS84_EARTH_FLATTENING),
52                              e.getB(),
53                              1.0e-15 * Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
54          Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_J, e.getU()), 1.0e-15);
55          Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_K, e.getU()), 1.0e-15);
56          Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_I, e.getV()), 1.0e-15);
57          Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(Vector3D.PLUS_J, e.getV()), 1.0e-15);
58      }
59  
60      @Test
61      public void testEquatorialShape() {
62          OneAxisEllipsoid model =
63                  new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
64                                       Constants.WGS84_EARTH_FLATTENING,
65                                       FramesFactory.getITRF(IERSConventions.IERS_2010, true));
66          Ellipse e = model.getPlaneSection(new Vector3D(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, 0, 0),
67                                            Vector3D.PLUS_K);
68          Assert.assertEquals(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
69                              e.getA(),
70                              1.0e-15 * Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
71          Assert.assertEquals(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
72                              e.getB(),
73                              1.0e-15 * Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
74      }
75  
76      @Test
77      public void testProjectionDerivatives() {
78          Ellipse e = new Ellipse(Vector3D.ZERO, Vector3D.PLUS_I, Vector3D.PLUS_J,
79                                  6.4e6, 6.3e6, FramesFactory.getGCRF());
80          TimeStampedPVCoordinates linearMotion =
81                  new TimeStampedPVCoordinates(AbsoluteDate.J2000_EPOCH,
82                                               new Vector3D(7.0e6, 5.0e6, 0.0),
83                                               new Vector3D(3.0e3, 4.0e3, 0.0),
84                                               Vector3D.ZERO);
85          TimeStampedPVCoordinates g0 = e.projectToEllipse(linearMotion);
86          List<TimeStampedPVCoordinates> sample = new ArrayList<TimeStampedPVCoordinates>();
87          for (double dt = -0.25; dt <= 0.25; dt += 0.125) {
88              sample.add(e.projectToEllipse(linearMotion.shiftedBy(dt)));
89          }
90          TimeStampedPVCoordinates ref = TimeStampedPVCoordinates.interpolate(g0.getDate(),
91                                                                              CartesianDerivativesFilter.USE_P,
92                                                                              sample);
93          Assert.assertEquals(0,
94                              Vector3D.distance(g0.getPosition(), ref.getPosition()) / ref.getPosition().getNorm(),
95                              1.0e-15);
96          Assert.assertEquals(0,
97                              Vector3D.distance(g0.getVelocity(), ref.getVelocity()) / ref.getVelocity().getNorm(),
98                              6.0e-12);
99          Assert.assertEquals(0,
100                             Vector3D.distance(g0.getAcceleration(), ref.getAcceleration()) / ref.getAcceleration().getNorm(),
101                             8.0e-8);
102 
103     }
104 
105     @Test
106     public void testMinRadiusOfCurvature() {
107         final double a = 100.0;
108         final double b =  50.0;
109         Ellipse e = new Ellipse(Vector3D.ZERO, Vector3D.PLUS_I, Vector3D.PLUS_J,
110                                 a, b, FramesFactory.getGCRF());
111         Vector2D point = new Vector2D(10 * a, 0.0);
112         Assert.assertEquals(b * b / a,
113                            Vector2D.distance(e.projectToEllipse(point), e.getCenterOfCurvature(point)),
114                            1.0e-15);
115     }
116 
117     @Test
118     public void testMaxRadiusOfCurvature() {
119         final double a = 100.0;
120         final double b =  50.0;
121         Ellipse e = new Ellipse(Vector3D.ZERO, Vector3D.PLUS_I, Vector3D.PLUS_J,
122                                 a, b, FramesFactory.getGCRF());
123         Vector2D point = new Vector2D(0.0, 10 * b);
124         Assert.assertEquals(a * a / b,
125                            Vector2D.distance(e.projectToEllipse(point), e.getCenterOfCurvature(point)),
126                            1.0e-15);
127     }
128 
129     @Test
130     public void testFlatEllipse() {
131         final double a = 0.839;
132         final double b = 0.176;
133         final Ellipse  ellipse   = new Ellipse(Vector3D.ZERO, Vector3D.PLUS_I, Vector3D.PLUS_J,
134                                                a, b, FramesFactory.getGCRF());
135         final Vector2D close = ellipse.projectToEllipse(new Vector2D(2.0, 4.0));
136         Assert.assertEquals(1.0,
137                             close.getX() * close.getX() / (a * a) + close.getY() * close.getY() / (b * b),
138                             1.0e-15);
139     }
140 
141     @Before
142     public void setUp() {
143         Utils.setDataRoot("regular-data");
144     }
145 
146 }
147