CircularFieldOfViewDetector.java

  1. /* Copyright 2002-2017 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.propagation.events;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.propagation.SpacecraftState;
  21. import org.orekit.propagation.events.handlers.EventHandler;
  22. import org.orekit.propagation.events.handlers.StopOnDecreasing;
  23. import org.orekit.utils.PVCoordinatesProvider;

  24. /** Finder for target entry/exit events with respect to a satellite sensor Field Of View.
  25.  * <p>This class handle fields of view with a circular boundary.</p>
  26.  * <p>The default implementation behavior is to {@link
  27.  * org.orekit.propagation.events.handlers.EventHandler.Action#CONTINUE continue}
  28.  * propagation at FOV entry and to {@link
  29.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop} propagation
  30.  * at FOV exit. This can be changed by calling
  31.  * {@link #withHandler(EventHandler)} after construction.</p>
  32.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  33.  * @see FieldOfViewDetector
  34.  * @author V&eacute;ronique Pommier-Maurussane
  35.  */
  36. public class CircularFieldOfViewDetector extends AbstractDetector<CircularFieldOfViewDetector> {

  37.     /** Serializable UID. */
  38.     private static final long serialVersionUID = 20131118L;

  39.     /** Position/velocity provider of the considered target. */
  40.     private final PVCoordinatesProvider targetPVProvider;

  41.     /** Direction of the FOV center. */
  42.     private final Vector3D center;

  43.     /** FOV half aperture angle. */
  44.     private final double halfAperture;

  45.     /** Build a new instance.
  46.      * <p>The maximal interval between distance to FOV boundary checks should
  47.      * be smaller than the half duration of the minimal pass to handle,
  48.      * otherwise some short passes could be missed.</p>
  49.      * @param maxCheck maximal interval in seconds
  50.      * @param pvTarget Position/velocity provider of the considered target
  51.      * @param center Direction of the FOV center, in spacecraft frame
  52.      * @param halfAperture FOV half aperture angle
  53.      */
  54.     public CircularFieldOfViewDetector(final double maxCheck,
  55.                                        final PVCoordinatesProvider pvTarget,
  56.                                        final Vector3D center,
  57.                                        final double halfAperture) {
  58.         this(maxCheck, 1.0e-3, DEFAULT_MAX_ITER, new StopOnDecreasing<CircularFieldOfViewDetector>(),
  59.              pvTarget, center, halfAperture);
  60.     }

  61.     /** Private constructor with full parameters.
  62.      * <p>
  63.      * This constructor is private as users are expected to use the builder
  64.      * API with the various {@code withXxx()} methods to set up the instance
  65.      * in a readable manner without using a huge amount of parameters.
  66.      * </p>
  67.      * @param maxCheck maximum checking interval (s)
  68.      * @param threshold convergence threshold (s)
  69.      * @param maxIter maximum number of iterations in the event time search
  70.      * @param handler event handler to call at event occurrences
  71.      * @param pvTarget Position/velocity provider of the considered target
  72.      * @param center Direction of the FOV center, in spacecraft frame
  73.      * @param halfAperture FOV half aperture angle
  74.      * @since 6.1
  75.      */
  76.     private CircularFieldOfViewDetector(final double maxCheck, final double threshold,
  77.                                         final int maxIter, final EventHandler<? super CircularFieldOfViewDetector> handler,
  78.                                         final PVCoordinatesProvider pvTarget,
  79.                                         final Vector3D center,
  80.                                         final double halfAperture) {
  81.         super(maxCheck, threshold, maxIter, handler);
  82.         this.targetPVProvider = pvTarget;
  83.         this.center           = center;
  84.         this.halfAperture     = halfAperture;
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     protected CircularFieldOfViewDetector create(final double newMaxCheck, final double newThreshold,
  89.                                                  final int newMaxIter, final EventHandler<? super CircularFieldOfViewDetector> newHandler) {
  90.         return new CircularFieldOfViewDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  91.                                                targetPVProvider, center, halfAperture);
  92.     }

  93.     /** Get the position/velocity provider of the target .
  94.      * @return the position/velocity provider of the target
  95.      */
  96.     public PVCoordinatesProvider getPVTarget() {
  97.         return targetPVProvider;
  98.     }

  99.     /** Get the direction of FOV center.
  100.      * @return the direction of FOV center
  101.      */
  102.     public Vector3D getCenter() {
  103.         return center;
  104.     }

  105.     /** Get FOV half aperture angle.
  106.      * @return the FOV half aperture angle
  107.      */
  108.     public double getHalfAperture() {
  109.         return halfAperture;
  110.     }

  111.     /** {@inheritDoc}
  112.      * <p>
  113.      * The g function value is the difference between FOV half aperture and the
  114.      * absolute value of the angle between target direction and field of view center.
  115.      * It is positive inside the FOV and negative outside.
  116.      * </p>
  117.      */
  118.     public double g(final SpacecraftState s) throws OrekitException {

  119.         // Compute target position/velocity at date in spacecraft frame
  120.         final Vector3D targetPosInert = new Vector3D(1, targetPVProvider.getPVCoordinates(s.getDate(), s.getFrame()).getPosition(),
  121.                                            -1, s.getPVCoordinates().getPosition());
  122.         final Vector3D targetPosSat = s.getAttitude().getRotation().applyTo(targetPosInert);

  123.         // Target is in the field of view if the absolute value that angle is smaller than FOV half aperture.
  124.         // g function value is the difference between FOV half aperture and the absolute value of the angle between
  125.         // target direction and field of view center. It is positive inside the FOV and negative outside.
  126.         return halfAperture - Vector3D.angle(targetPosSat, center);
  127.     }

  128. }