ThirdBodyAttraction.java

  1. /* Copyright 2002-2024 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.forces.gravity;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.orekit.bodies.CelestialBodies;
  23. import org.orekit.bodies.CelestialBody;
  24. import org.orekit.propagation.FieldSpacecraftState;
  25. import org.orekit.propagation.SpacecraftState;

  26. /** Third body attraction force model.
  27.  *
  28.  * @author Fabien Maussion
  29.  * @author Véronique Pommier-Maurussane
  30.  */
  31. public class ThirdBodyAttraction extends AbstractBodyAttraction {

  32.     /** Simple constructor.
  33.      * @param body the third body to consider
  34.      * (ex: {@link CelestialBodies#getSun()} or
  35.      * {@link CelestialBodies#getMoon()})
  36.      */
  37.     public ThirdBodyAttraction(final CelestialBody body) {
  38.         super(body);
  39.     }

  40.     /** {@inheritDoc} */
  41.     @Override
  42.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  43.         final double gm = parameters[0];

  44.         // compute bodies separation vectors and squared norm
  45.         final Vector3D centralToBody = getBody().getPosition(s.getDate(), s.getFrame());
  46.         final double r2Central       = centralToBody.getNormSq();
  47.         final Vector3D satToBody     = centralToBody.subtract(s.getPosition());
  48.         final double r2Sat           = satToBody.getNormSq();

  49.         // compute relative acceleration
  50.         return new Vector3D(gm / (r2Sat * FastMath.sqrt(r2Sat)), satToBody,
  51.                            -gm / (r2Central * FastMath.sqrt(r2Central)), centralToBody);

  52.     }

  53.     /** {@inheritDoc} */
  54.     @Override
  55.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  56.                                                                              final T[] parameters) {

  57.         final T gm = parameters[0];

  58.         // compute bodies separation vectors and squared norm
  59.         final FieldVector3D<T> centralToBody = getBody().getPosition(s.getDate(), s.getFrame());
  60.         final T                r2Central     = centralToBody.getNormSq();
  61.         final FieldVector3D<T> satToBody     = centralToBody.subtract(s.getPosition());
  62.         final T                r2Sat         = satToBody.getNormSq();

  63.         // compute relative acceleration
  64.         return new FieldVector3D<>(r2Sat.multiply(r2Sat.sqrt()).reciprocal().multiply(gm), satToBody,
  65.                                    r2Central.multiply(r2Central.sqrt()).reciprocal().multiply(gm).negate(), centralToBody);

  66.     }

  67. }