FieldStaticTransform.java

  1. /* Copyright 2002-2023 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.Field;
  20. import org.hipparchus.geometry.euclidean.threed.FieldLine;
  21. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  22. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  23. import org.hipparchus.geometry.euclidean.threed.Line;
  24. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  25. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.time.FieldAbsoluteDate;
  28. import org.orekit.time.TimeStamped;

  29. /**
  30.  * A transform that only includes translation and rotation. It is static in the
  31.  * sense that no rates thereof are included.
  32.  *
  33.  * @param <T> the type of the field elements
  34.  * @author Bryan Cazabonne
  35.  * @see FieldTransform
  36.  * @since 12.0
  37.  */
  38. public interface FieldStaticTransform<T extends CalculusFieldElement<T>> extends TimeStamped {

  39.     /**
  40.      * Get the identity static transform.
  41.      *
  42.      * @param <T> type of the elements
  43.      * @param field field used by default
  44.      * @return identity transform.
  45.      */
  46.     static <T extends CalculusFieldElement<T>> FieldStaticTransform<T> getIdentity(final Field<T> field) {
  47.         return FieldTransform.getIdentity(field);
  48.     }

  49.     /**
  50.      * Transform a position vector (including translation effects).
  51.      *
  52.      * @param position vector to transform
  53.      * @return transformed position
  54.      */
  55.     default FieldVector3D<T> transformPosition(final Vector3D position) {
  56.         return getRotation().applyTo(getTranslation().add(position));
  57.     }

  58.     /**
  59.      * Transform a position vector (including translation effects).
  60.      *
  61.      * @param position vector to transform
  62.      * @return transformed position
  63.      */
  64.     default FieldVector3D<T> transformPosition(final FieldVector3D<T> position) {
  65.         return getRotation().applyTo(position.add(getTranslation()));
  66.     }

  67.     /**
  68.      * Transform a vector (ignoring translation effects).
  69.      *
  70.      * @param vector vector to transform
  71.      * @return transformed vector
  72.      */
  73.     default FieldVector3D<T> transformVector(final Vector3D vector) {
  74.         return getRotation().applyTo(vector);
  75.     }

  76.     /**
  77.      * Transform a vector (ignoring translation effects).
  78.      *
  79.      * @param vector vector to transform
  80.      * @return transformed vector
  81.      */
  82.     default FieldVector3D<T> transformVector(final FieldVector3D<T> vector) {
  83.         return getRotation().applyTo(vector);
  84.     }

  85.     /**
  86.      * Transform a line.
  87.      *
  88.      * @param line to transform
  89.      * @return transformed line
  90.      */
  91.     default FieldLine<T> transformLine(final Line line) {
  92.         final FieldVector3D<T> transformedP0 = transformPosition(line.getOrigin());
  93.         final FieldVector3D<T> transformedP1 = transformPosition(line.pointAt(1.0e6));
  94.         return new FieldLine<>(transformedP0, transformedP1, line.getTolerance());
  95.     }

  96.     /**
  97.      * Transform a line.
  98.      *
  99.      * @param line to transform
  100.      * @return transformed line
  101.      */
  102.     default FieldLine<T> transformLine(final FieldLine<T> line) {
  103.         final FieldVector3D<T> transformedP0 = transformPosition(line.getOrigin());
  104.         final FieldVector3D<T> transformedP1 = transformPosition(line.pointAt(1.0e6));
  105.         return new FieldLine<>(transformedP0, transformedP1, line.getTolerance());
  106.     }

  107.     /**
  108.      * Get the underlying elementary translation.
  109.      * <p>A transform can be uniquely represented as an elementary
  110.      * translation followed by an elementary rotation. This method returns this
  111.      * unique elementary translation.</p>
  112.      *
  113.      * @return underlying elementary translation
  114.      */
  115.     FieldVector3D<T> getTranslation();

  116.     /**
  117.      * Get the underlying elementary rotation.
  118.      * <p>A transform can be uniquely represented as an elementary
  119.      * translation followed by an elementary rotation. This method returns this
  120.      * unique elementary rotation.</p>
  121.      *
  122.      * @return underlying elementary rotation
  123.      */
  124.     FieldRotation<T> getRotation();

  125.     /**
  126.      * Get the inverse transform of the instance.
  127.      *
  128.      * @return inverse transform of the instance
  129.      */
  130.     FieldStaticTransform<T> getInverse();

  131.     /**
  132.      * Build a transform by combining two existing ones.
  133.      * <p>
  134.      * Note that the dates of the two existing transformed are <em>ignored</em>,
  135.      * and the combined transform date is set to the date supplied in this
  136.      * constructor without any attempt to shift the raw transforms. This is a
  137.      * design choice allowing user full control of the combination.
  138.      * </p>
  139.      *
  140.      * @param <T>    type of the elements
  141.      * @param date   date of the transform
  142.      * @param first  first transform applied
  143.      * @param second second transform applied
  144.      * @return the newly created static transform that has the same effect as
  145.      * applying {@code first}, then {@code second}.
  146.      * @see #of(FieldAbsoluteDate, FieldVector3D, FieldRotation)
  147.      */
  148.     static <T extends CalculusFieldElement<T>> FieldStaticTransform<T> compose(final FieldAbsoluteDate<T> date,
  149.                                                                                final FieldStaticTransform<T> first,
  150.                                                                                final FieldStaticTransform<T> second) {
  151.         return of(date,
  152.                   compositeTranslation(first, second),
  153.                   compositeRotation(first, second));
  154.     }

  155.     /**
  156.      * Compute a composite translation.
  157.      *
  158.      * @param first first applied transform
  159.      * @param second second applied transform
  160.      * @param <T> the type of the field elements
  161.      * @return translation part of the composite transform
  162.      */
  163.     static <T extends CalculusFieldElement<T>> FieldVector3D<T> compositeTranslation(final FieldStaticTransform<T> first,
  164.                                                                                      final FieldStaticTransform<T> second) {

  165.         final FieldVector3D<T> p1 = first.getTranslation();
  166.         final FieldRotation<T> r1 = first.getRotation();
  167.         final FieldVector3D<T> p2 = second.getTranslation();

  168.         return p1.add(r1.applyInverseTo(p2));

  169.     }

  170.     /**
  171.      * Compute a composite rotation.
  172.      *
  173.      * @param first first applied transform
  174.      * @param second second applied transform
  175.      * @param <T> the type of the field elements
  176.      * @return rotation part of the composite transform
  177.      */
  178.     static <T extends CalculusFieldElement<T>> FieldRotation<T> compositeRotation(final FieldStaticTransform<T> first,
  179.                                                                                   final FieldStaticTransform<T> second) {
  180.         final FieldRotation<T> r1 = first.getRotation();
  181.         final FieldRotation<T> r2 = second.getRotation();
  182.         return r1.compose(r2, RotationConvention.FRAME_TRANSFORM);
  183.     }

  184.     /**
  185.      * Create a new static transform from a rotation and zero translation.
  186.      *
  187.      * @param <T>         type of the elements
  188.      * @param date     of translation.
  189.      * @param rotation to apply after the translation. That is after translating
  190.      *                 applying this rotation produces positions expressed in
  191.      *                 the new frame.
  192.      * @return the newly created static transform.
  193.      * @see #of(FieldAbsoluteDate, FieldVector3D, FieldRotation)
  194.      */
  195.     static <T extends CalculusFieldElement<T>> FieldStaticTransform<T> of(final FieldAbsoluteDate<T> date,
  196.                                                                           final FieldRotation<T> rotation) {
  197.         return of(date, FieldVector3D.getZero(date.getField()), rotation);
  198.     }

  199.     /**
  200.      * Create a new static transform from a translation and rotation.
  201.      *
  202.      * @param <T>         type of the elements
  203.      * @param date        of translation.
  204.      * @param translation to apply, expressed in the old frame. That is, the
  205.      *                    opposite of the coordinates of the new origin in the
  206.      *                    old frame.
  207.      * @return the newly created static transform.
  208.      * @see #of(FieldAbsoluteDate, FieldVector3D, FieldRotation)
  209.      */
  210.     static <T extends CalculusFieldElement<T>> FieldStaticTransform<T> of(final FieldAbsoluteDate<T> date,
  211.                                                                           final FieldVector3D<T> translation) {
  212.         return of(date, translation, FieldRotation.getIdentity(date.getField()));
  213.     }

  214.     /**
  215.      * Create a new static transform from an {@link FieldAbsoluteDate} and a {@link StaticTransform}.
  216.      *
  217.      * @param <T>         type of the elements
  218.      * @param date        of translation.
  219.      * @param staticTransform to apply
  220.      * @return the newly created static transform.
  221.      * @see #of(FieldAbsoluteDate, FieldVector3D, FieldRotation)
  222.      */
  223.     static <T extends CalculusFieldElement<T>> FieldStaticTransform<T> of(final FieldAbsoluteDate<T> date,
  224.                                                                           final StaticTransform staticTransform) {
  225.         return of(date,
  226.                   new FieldVector3D<>(date.getField(), staticTransform.getTranslation()),
  227.                   new FieldRotation<>(date.getField(), staticTransform.getRotation()));
  228.     }

  229.     /**
  230.      * Create a new static transform from a translation and rotation.
  231.      *
  232.      * @param <T>         type of the elements
  233.      * @param date        of translation.
  234.      * @param translation to apply, expressed in the old frame. That is, the
  235.      *                    opposite of the coordinates of the new origin in the
  236.      *                    old frame.
  237.      * @param rotation    to apply after the translation. That is after
  238.      *                    translating applying this rotation produces positions
  239.      *                    expressed in the new frame.
  240.      * @return the newly created static transform.
  241.      * @see #compose(FieldAbsoluteDate, FieldStaticTransform, FieldStaticTransform)
  242.      * @see #of(FieldAbsoluteDate, FieldRotation)
  243.      * @see #of(FieldAbsoluteDate, FieldVector3D)
  244.      */
  245.     static <T extends CalculusFieldElement<T>> FieldStaticTransform<T> of(final FieldAbsoluteDate<T> date,
  246.                                                                           final FieldVector3D<T> translation,
  247.                                                                           final FieldRotation<T> rotation) {
  248.         return new FieldStaticTransform<T>() {

  249.             @Override
  250.             public FieldStaticTransform<T> getInverse() {
  251.                 final FieldRotation<T> r = getRotation();
  252.                 final FieldVector3D<T> rp = r.applyTo(getTranslation());
  253.                 final FieldVector3D<T> pInv = rp.negate();
  254.                 return FieldStaticTransform.of(date, pInv, rotation.revert());
  255.             }

  256.             @Override
  257.             public AbsoluteDate getDate() {
  258.                 return date.toAbsoluteDate();
  259.             }

  260.             @Override
  261.             public FieldVector3D<T> getTranslation() {
  262.                 return translation;
  263.             }

  264.             @Override
  265.             public FieldRotation<T> getRotation() {
  266.                 return rotation;
  267.             }

  268.         };
  269.     }

  270. }