1   /* Copyright 2002-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  
18  package org.orekit.frames;
19  
20  import org.hamcrest.CoreMatchers;
21  import org.hamcrest.MatcherAssert;
22  import org.hipparchus.complex.Complex;
23  import org.hipparchus.complex.ComplexField;
24  import org.hipparchus.geometry.euclidean.threed.*;
25  import org.hipparchus.util.FastMath;
26  import org.junit.jupiter.api.Assertions;
27  import org.junit.jupiter.api.Test;
28  import org.orekit.OrekitMatchers;
29  import org.orekit.time.AbsoluteDate;
30  
31  /**
32   * Unit tests for {@link StaticTransform}.
33   *
34   * @author Evan Ward
35   */
36  public class StaticTransformTest {
37  
38      /** Test creating, composing, and using a StaticTransform. */
39      @Test
40      public void testSimpleComposition() {
41          // setup
42          Rotation rotation = new Rotation(
43                  Vector3D.PLUS_K, 0.5 * FastMath.PI,
44                  RotationConvention.VECTOR_OPERATOR);
45          AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
46  
47          // action
48          StaticTransform transform = StaticTransform.compose(
49                  date,
50                  StaticTransform.of(date, rotation),
51                  StaticTransform.of(date, Vector3D.PLUS_I));
52          StaticTransform identity = StaticTransform
53                  .compose(date, transform, transform.getInverse());
54  
55          // verify
56          double tol = 1e-15;
57          Vector3D u = transform.transformPosition(new Vector3D(1.0, 1.0, 1.0));
58          Vector3D v = new Vector3D(0.0, 1.0, 1.0);
59          MatcherAssert.assertThat(u, OrekitMatchers.vectorCloseTo(v, tol));
60          Vector3D w = transform.transformVector(new Vector3D(1, 2, 3));
61          Vector3D x = new Vector3D(-2, 1, 3);
62          MatcherAssert.assertThat(w, OrekitMatchers.vectorCloseTo(x, tol));
63          MatcherAssert.assertThat(transform.getTranslation(),
64                  OrekitMatchers.vectorCloseTo(Vector3D.MINUS_J, tol));
65          MatcherAssert.assertThat(transform.getRotation().getAngle(),
66                  CoreMatchers.is(rotation.getAngle()));
67          MatcherAssert.assertThat(transform.getRotation().getAxis(RotationConvention.VECTOR_OPERATOR),
68                  CoreMatchers.is(rotation.getAxis(RotationConvention.VECTOR_OPERATOR)));
69          MatcherAssert.assertThat(
70                  identity.transformPosition(u),
71                  OrekitMatchers.vectorCloseTo(u, tol));
72          MatcherAssert.assertThat(
73                  identity.transformVector(u),
74                  OrekitMatchers.vectorCloseTo(u, tol));
75          // check line transform
76          Vector3D p1 = new Vector3D(42.1e6, 42.1e6, 42.1e6);
77          Vector3D d = new Vector3D(-42e6, 42e6, -42e6);
78          Line line = Line.fromDirection(p1, d, 0);
79          Line actualLine = transform.transformLine(line);
80          MatcherAssert.assertThat(
81                  actualLine.getDirection(),
82                  OrekitMatchers.vectorCloseTo(transform.transformVector(d).normalize(), 1));
83          // account for translation
84          Vector3D expectedOrigin = new Vector3D(
85                 -56133332.666666666, 28066666.333333333, 28066666.333333333);
86          MatcherAssert.assertThat(
87                  actualLine.getOrigin(),
88                  OrekitMatchers.vectorCloseTo(expectedOrigin, 3));
89          MatcherAssert.assertThat(
90                  actualLine.getTolerance(),
91                  CoreMatchers.is(line.getTolerance()));
92      }
93  
94      @Test
95      void testGetStaticInverse() {
96          // GIVEN
97          final AbsoluteDate date = AbsoluteDate.ARBITRARY_EPOCH;
98          final Vector3D translation = new Vector3D(1., 2., 3.);
99          final Rotation rotation = new Rotation(Vector3D.MINUS_J, Vector3D.PLUS_I);
100         final StaticTransform staticTransform = StaticTransform.of(date, translation, rotation);
101         // WHEN
102         final StaticTransform actualInverseStaticTransform = staticTransform.getStaticInverse();
103         // THEN
104         final StaticTransform expectedInverseStaticTransform = staticTransform.getInverse();
105         Assertions.assertEquals(expectedInverseStaticTransform.getDate(), actualInverseStaticTransform.getDate());
106         Assertions.assertEquals(expectedInverseStaticTransform.getTranslation(),
107                 actualInverseStaticTransform.getTranslation());
108         Assertions.assertEquals(0., Rotation.distance(expectedInverseStaticTransform.getRotation(),
109                 actualInverseStaticTransform.getRotation()));
110     }
111 
112     @Test
113     void testGetIdentity() {
114         // GIVEN
115         final StaticTransform identity = StaticTransform.getIdentity();
116         final Vector3D vector3D = new Vector3D(1, 2, 3);
117         final FieldVector3D<Complex> fieldVector3D = new FieldVector3D<>(ComplexField.getInstance(), vector3D);
118         // WHEN & THEN
119         Assertions.assertEquals(AbsoluteDate.ARBITRARY_EPOCH, identity.getDate());
120         Assertions.assertEquals(identity.transformVector(vector3D), identity.getRotation().applyTo(vector3D));
121         Assertions.assertEquals(identity.transformPosition(vector3D),
122                 identity.getRotation().applyTo(vector3D).add(identity.getTranslation()));
123         Assertions.assertEquals(identity.transformVector(vector3D), identity.getRotation().applyTo(vector3D));
124         Assertions.assertEquals(identity.transformVector(fieldVector3D).toVector3D(),
125                 identity.getRotation().applyTo(fieldVector3D.toVector3D()));
126         Assertions.assertEquals(identity.transformPosition(fieldVector3D).toVector3D(),
127                 identity.getTranslation().add(identity.getRotation().applyTo(fieldVector3D.toVector3D())));
128         Assertions.assertEquals(identity, identity.getStaticInverse());
129         Assertions.assertEquals(identity, identity.getInverse());
130     }
131 }