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  package org.orekit.frames;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.orekit.bodies.CelestialBody;
23  import org.orekit.time.AbsoluteDate;
24  import org.orekit.time.FieldAbsoluteDate;
25  import org.orekit.utils.FieldPVCoordinates;
26  import org.orekit.utils.PVCoordinates;
27  
28  /** Transform provider for the inertial Barycentered frame.
29   * @author Vincent Mouraux
30   * @since 10.2
31   */
32  class TwoBodiesBaryTransformProvider implements TransformProvider {
33  
34      /** Frame for results. Always defined as primaryBody's inertially oriented frame.*/
35      private final Frame frame;
36  
37      /** Celestial body with bigger mass, m1. */
38      private final CelestialBody primaryBody;
39  
40      /** Celestial body with smaller mass, m2. */
41      private final CelestialBody secondaryBody;
42  
43  
44      /** Simple constructor.
45       * @param primaryBody Primary body.
46       * @param secondaryBody Secondary body.
47       */
48      TwoBodiesBaryTransformProvider(final CelestialBody primaryBody, final CelestialBody secondaryBody) {
49          this.primaryBody = primaryBody;
50          this.secondaryBody = secondaryBody;
51          this.frame = primaryBody.getInertiallyOrientedFrame();
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      public Transform getTransform(final AbsoluteDate date) {
57          final PVCoordinates pv21 = secondaryBody.getPVCoordinates(date, frame);
58          final double massRatio = secondaryBody.getGM() / (primaryBody.getGM() + secondaryBody.getGM());
59          final Vector3D translation = pv21.getPosition().scalarMultiply(massRatio).negate();
60          return new Transform(date, translation);
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
66          final FieldPVCoordinates<T> pv21        = secondaryBody.getPVCoordinates(date, frame);
67          final double massRatio = secondaryBody.getGM() / (primaryBody.getGM() + secondaryBody.getGM());
68          final FieldVector3D<T> translation = pv21.getPosition().scalarMultiply(massRatio).negate();
69          return new FieldTransform<>(date, translation);
70      }
71  }