1   /* Copyright 2002-2023 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  
18  package org.orekit.utils;
19  
20  import org.hipparchus.CalculusFieldElement;
21  import org.orekit.frames.FieldTransform;
22  import org.orekit.frames.Frame;
23  import org.orekit.frames.Transform;
24  import org.orekit.frames.TransformProvider;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.FieldAbsoluteDate;
27  
28  /** Adapter from {@link ExtendedPVCoordinatesProvider} to {@link TransformProvider}.
29   * <p>
30   * The transform provider is a simple translation from a defining frame such
31   * that the origin of the transformed frame corresponds to the moving point.
32   * </p>
33   * <p>
34   * This class is roughly the inverse of {@link FrameAdapter}
35   * </p>
36   * @see FrameAdapter
37   * @since 12.0
38   * @author Luc Maisonobe
39   */
40  public class ExtendedPVCoordinatesProviderAdapter extends Frame {
41  
42      /** Serializable UID. */
43      private static final long serialVersionUID = 20221215L;
44  
45      /** Simple constructor.
46       * @param parent parent frame (must be non-null)
47       * @param provider coordinates provider defining the position of origin of the transformed frame
48       * @param name name of the frame
49       */
50      public ExtendedPVCoordinatesProviderAdapter(final Frame parent,
51                                                  final ExtendedPVCoordinatesProvider provider,
52                                                  final String name) {
53          super(parent, new TransformProvider() {
54  
55              /** Serializable UID. */
56              private static final long serialVersionUID = 20221215L;
57  
58              /** {@inheritDoc} */
59              @Override
60              public Transform getTransform(final AbsoluteDate date) {
61                  return new Transform(date, provider.getPVCoordinates(date, parent).negate());
62              }
63  
64              /** {@inheritDoc} */
65              @Override
66              public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
67                  return new FieldTransform<>(date, provider.getPVCoordinates(date, parent).negate());
68              }
69  
70          }, name);
71      }
72  
73  }