TwoBodiesBaryTransformProvider.java

  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. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.orekit.bodies.CelestialBody;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.time.FieldAbsoluteDate;
  24. import org.orekit.utils.FieldPVCoordinates;
  25. import org.orekit.utils.PVCoordinates;

  26. /** Transform provider for the inertial Barycentered frame.
  27.  * @author Vincent Mouraux
  28.  * @since 10.2
  29.  */
  30. class TwoBodiesBaryTransformProvider implements TransformProvider {

  31.     /** Frame for results. Always defined as primaryBody's inertially oriented frame.*/
  32.     private final Frame frame;

  33.     /** Celestial body with bigger mass, m1. */
  34.     private final CelestialBody primaryBody;

  35.     /** Celestial body with smaller mass, m2. */
  36.     private final CelestialBody secondaryBody;


  37.     /** Simple constructor.
  38.      * @param primaryBody Primary body.
  39.      * @param secondaryBody Secondary body.
  40.      */
  41.     TwoBodiesBaryTransformProvider(final CelestialBody primaryBody, final CelestialBody secondaryBody) {
  42.         this.primaryBody = primaryBody;
  43.         this.secondaryBody = secondaryBody;
  44.         this.frame = primaryBody.getInertiallyOrientedFrame();
  45.     }

  46.     /** {@inheritDoc} */
  47.     @Override
  48.     public Transform getTransform(final AbsoluteDate date) {
  49.         final PVCoordinates pv21 = secondaryBody.getPVCoordinates(date, frame);
  50.         final double massRatio = secondaryBody.getGM() / (primaryBody.getGM() + secondaryBody.getGM());
  51.         final Vector3D translation = pv21.getPosition().scalarMultiply(massRatio).negate();
  52.         return new Transform(date, translation);
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  57.         final FieldPVCoordinates<T> pv21        = secondaryBody.getPVCoordinates(date, frame);
  58.         final double massRatio = secondaryBody.getGM() / (primaryBody.getGM() + secondaryBody.getGM());
  59.         final FieldVector3D<T> translation = pv21.getPosition().scalarMultiply(massRatio).negate();
  60.         return new FieldTransform<>(date, translation);
  61.     }
  62. }