CartesianCovarianceUtils.java

  1. /* Copyright 2022-2025 Romain Serra
  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.utils;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.linear.MatrixUtils;
  20. import org.hipparchus.linear.RealMatrix;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.frames.KinematicTransform;
  23. import org.orekit.frames.LOFType;
  24. import org.orekit.frames.Transform;
  25. import org.orekit.time.AbsoluteDate;

  26. /**
  27.  * Utility class for conversions related to Cartesian covariance matrices.
  28.  *
  29.  * @author Romain Serra
  30.  * @since 12.2
  31.  */
  32. public class CartesianCovarianceUtils {

  33.     /**
  34.      * Private constructor.
  35.      */
  36.     private CartesianCovarianceUtils() {
  37.         // utility class
  38.     }

  39.     /**
  40.      * Convert input position-velocity covariance matrix between reference frames.
  41.      * @param inputFrame input frame
  42.      * @param outputFrame output frame
  43.      * @param covarianceMatrix position-velocity covariance matrix in reference frame
  44.      * @param date epoch
  45.      * @return converted covariance matrix
  46.      */
  47.     public static RealMatrix changeReferenceFrame(final Frame inputFrame, final RealMatrix covarianceMatrix,
  48.                                                   final AbsoluteDate date, final Frame outputFrame) {
  49.         final KinematicTransform kinematicTransform = inputFrame.getKinematicTransformTo(outputFrame, date);
  50.         return changePositionVelocityFrame(covarianceMatrix, kinematicTransform);
  51.     }

  52.     /**
  53.      * Convert input position-velocity covariance matrix from reference frame to local one.
  54.      * @param position position vector in reference frame
  55.      * @param velocity velocity vector in reference frame
  56.      * @param covarianceMatrix position-velocity covariance matrix in reference frame
  57.      * @param lofType output local orbital frame
  58.      * @return converted covariance matrix
  59.      */
  60.     public static RealMatrix convertToLofType(final Vector3D position, final Vector3D velocity,
  61.                                               final RealMatrix covarianceMatrix, final LOFType lofType) {
  62.         final Transform transformFromInertial = transformToLofType(lofType, position, velocity);
  63.         return changePositionVelocityFrame(covarianceMatrix, transformFromInertial);
  64.     }

  65.     /**
  66.      * Convert input position-velocity covariance matrix from local frame to reference one.
  67.      * @param position position vector in reference frame
  68.      * @param velocity velocity vector in reference frame
  69.      * @param covarianceMatrix position-velocity covariance matrix in local frame
  70.      * @param lofType input local orbital frame
  71.      * @return converted covariance matrix
  72.      */
  73.     public static RealMatrix convertFromLofType(final LOFType lofType, final RealMatrix covarianceMatrix,
  74.                                                 final Vector3D position, final Vector3D velocity) {
  75.         final Transform transformFromInertial = transformToLofType(lofType, position, velocity);
  76.         return changePositionVelocityFrame(covarianceMatrix, transformFromInertial.getInverse());
  77.     }

  78.     /**
  79.      * Get the transform from local orbital frame to reference frame.
  80.      * @param lofType input local frame type
  81.      * @param position position in reference frame
  82.      * @param velocity velocity in reference frame
  83.      * @return transform
  84.      */
  85.     private static Transform transformToLofType(final LOFType lofType, final Vector3D position,
  86.                                                 final Vector3D velocity) {
  87.         return lofType.transformFromInertial(null, new PVCoordinates(position, velocity));
  88.     }

  89.     /**
  90.      * Convert the input position-velocity covariance matrix according to input transformation.
  91.      * @param covarianceMatrix original covariance matrix
  92.      * @param kinematicTransform kinematic frame transform
  93.      * @return transformed covariance matrix
  94.      */
  95.     private static RealMatrix changePositionVelocityFrame(final RealMatrix covarianceMatrix,
  96.                                                           final KinematicTransform kinematicTransform) {
  97.         final RealMatrix jacobianTransformPV = MatrixUtils.createRealMatrix(kinematicTransform.getPVJacobian());
  98.         return jacobianTransformPV.multiply(covarianceMatrix.multiplyTransposed(jacobianTransformPV));
  99.     }
  100. }