GroundPointTarget.java

  1. /* Copyright 2022-2025 Luc Maisonobe
  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.attitudes;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.analysis.differentiation.FieldUnivariateDerivative2;
  21. import org.hipparchus.analysis.differentiation.UnivariateDerivative2;
  22. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.orekit.bodies.OneAxisEllipsoid;
  25. import org.orekit.frames.FieldTransform;
  26. import org.orekit.frames.FieldStaticTransform;
  27. import org.orekit.frames.Frame;
  28. import org.orekit.frames.StaticTransform;
  29. import org.orekit.frames.Transform;
  30. import org.orekit.utils.ExtendedPositionProvider;
  31. import org.orekit.utils.FieldPVCoordinates;
  32. import org.orekit.utils.PVCoordinates;
  33. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  34. import org.orekit.utils.TimeStampedPVCoordinates;

  35. import java.util.HashMap;
  36. import java.util.Map;

  37. /**
  38.  * Ground point target for {@link AlignedAndConstrained}.
  39.  * @author Luc Maisonobe
  40.  * @since 12.2
  41.  */
  42. public class GroundPointTarget implements TargetProvider
  43. {

  44.     /** Location of the target in Earth frame. */
  45.     private final PVCoordinates location;

  46.     /** Cached field-based locations. */
  47.     private final transient Map<Field<? extends CalculusFieldElement<?>>, FieldPVCoordinates<?>>
  48.         cachedLocations;

  49.     /** Simple constructor.
  50.      * @param location location of the target in Earth frame
  51.      */
  52.     public GroundPointTarget(final Vector3D location)
  53.     {
  54.         this.location        = new PVCoordinates(location, Vector3D.ZERO, Vector3D.ZERO);
  55.         this.cachedLocations = new HashMap<>();
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public FieldVector3D<UnivariateDerivative2> getDerivative2TargetDirection(final ExtendedPositionProvider sun,
  60.                                                                               final OneAxisEllipsoid earth,
  61.                                                                               final TimeStampedPVCoordinates pv,
  62.                                                                               final Frame frame) {
  63.         final Transform earthToInert = earth.getFrame().getTransformTo(frame, pv.getDate());
  64.         return new PVCoordinates(pv, earthToInert.transformPVCoordinates(location)).
  65.                toUnivariateDerivative2Vector().
  66.                normalize();
  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public Vector3D getTargetDirection(final ExtendedPositionProvider sun, final OneAxisEllipsoid earth,
  71.                                             final TimeStampedPVCoordinates pv, final Frame frame) {
  72.         final StaticTransform earthToInert = earth.getFrame().getStaticTransformTo(frame, pv.getDate());
  73.         return earthToInert.transformPosition(location.getPosition()).subtract(pv.getPosition()).normalize();
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     public <T extends CalculusFieldElement<T>> FieldVector3D<FieldUnivariateDerivative2<T>> getDerivative2TargetDirection(final ExtendedPositionProvider sun,
  78.                                                                                                                           final OneAxisEllipsoid earth,
  79.                                                                                                                           final TimeStampedFieldPVCoordinates<T> pv,
  80.                                                                                                                           final Frame frame) {
  81.         final Field<T> field = pv.getDate().getField();

  82.         // get the target location for specified field
  83.         @SuppressWarnings("unchecked")
  84.         final FieldPVCoordinates<T> l =
  85.             (FieldPVCoordinates<T>) cachedLocations.computeIfAbsent(field, f -> {
  86.                 final T zero = field.getZero();
  87.                 return new FieldPVCoordinates<>(new FieldVector3D<>(zero.newInstance(location.getPosition().getX()),
  88.                                                                     zero.newInstance(location.getPosition().getY()),
  89.                                                                     zero.newInstance(location.getPosition().getZ())),
  90.                                                 FieldVector3D.getZero(field),
  91.                                                 FieldVector3D.getZero(field));
  92.             });

  93.         final FieldTransform<T> earthToInert = earth.getFrame().getTransformTo(frame, pv.getDate());
  94.         return new FieldPVCoordinates<>(pv, earthToInert.transformPVCoordinates(l)).
  95.                toUnivariateDerivative2Vector().
  96.                normalize();

  97.     }

  98.     /** {@inheritDoc} */
  99.     @Override
  100.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> getTargetDirection(final ExtendedPositionProvider sun,
  101.                                                                                    final OneAxisEllipsoid earth,
  102.                                                                                    final TimeStampedFieldPVCoordinates<T> pv,
  103.                                                                                    final Frame frame) {
  104.         final FieldStaticTransform<T> earthToInert = earth.getFrame().getStaticTransformTo(frame, pv.getDate());
  105.         return earthToInert.transformPosition(location.getPosition()).subtract(pv.getPosition()).normalize();
  106.     }
  107. }