DoubleDihedraFieldOfView.java

  1. /* Copyright 2002-2021 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.geometry.fov;

  18. import org.hipparchus.exception.LocalizedCoreFormats;
  19. import org.hipparchus.geometry.euclidean.threed.Rotation;
  20. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.hipparchus.geometry.partitioning.Region;
  23. import org.hipparchus.geometry.partitioning.RegionFactory;
  24. import org.hipparchus.geometry.spherical.twod.Sphere2D;
  25. import org.hipparchus.geometry.spherical.twod.SphericalPolygonsSet;
  26. import org.hipparchus.util.FastMath;
  27. import org.orekit.errors.OrekitException;

  28. /** Class representing a spacecraft sensor Field Of View with dihedral shape (i.e. rectangular shape).
  29.  * @author Luc Maisonobe
  30.  * @since 10.1
  31.  */
  32. public class DoubleDihedraFieldOfView extends PolygonalFieldOfView {

  33.     /** Build a Field Of View with dihedral shape (i.e. rectangular shape).
  34.      * @param center Direction of the FOV center, in spacecraft frame
  35.      * @param axis1 FOV dihedral axis 1, in spacecraft frame
  36.      * @param halfAperture1 FOV dihedral half aperture angle 1,
  37.      * must be less than π/2, i.e. full dihedra must be smaller then
  38.      * an hemisphere
  39.      * @param axis2 FOV dihedral axis 2, in spacecraft frame
  40.      * @param halfAperture2 FOV dihedral half aperture angle 2,
  41.      * must be less than π/2, i.e. full dihedra must be smaller then
  42.      * an hemisphere
  43.      * @param margin angular margin to apply to the zone (if positive,
  44.      * points outside of the raw FoV but close enough to the boundary are
  45.      * considered visible; if negative, points inside of the raw FoV
  46.      * but close enough to the boundary are considered not visible)
  47.      */
  48.     public DoubleDihedraFieldOfView(final Vector3D center,
  49.                                     final Vector3D axis1, final double halfAperture1,
  50.                                     final Vector3D axis2, final double halfAperture2,
  51.                                     final double margin) {
  52.         super(createPolygon(center, axis1, halfAperture1, axis2, halfAperture2), margin);
  53.     }

  54.     /** Create polygon.
  55.      * @param center Direction of the FOV center, in spacecraft frame
  56.      * @param axis1 FOV dihedral axis 1, in spacecraft frame
  57.      * @param halfAperture1 FOV dihedral half aperture angle 1,
  58.      * must be less than π/2, i.e. full dihedra must be smaller then
  59.      * an hemisphere
  60.      * @param axis2 FOV dihedral axis 2, in spacecraft frame
  61.      * @param halfAperture2 FOV dihedral half aperture angle 2,
  62.      * must be less than π/2, i.e. full dihedra must be smaller then
  63.      * an hemisphere
  64.      * @return built polygon
  65.      */
  66.     private static SphericalPolygonsSet createPolygon(final Vector3D center,
  67.                                                       final Vector3D axis1, final double halfAperture1,
  68.                                                       final Vector3D axis2, final double halfAperture2) {
  69.         final RegionFactory<Sphere2D> factory = new RegionFactory<Sphere2D>();
  70.         final double tolerance = FastMath.max(FastMath.ulp(2.0 * FastMath.PI),
  71.                                               1.0e-12 * FastMath.max(halfAperture1, halfAperture2));
  72.         final Region<Sphere2D> dihedra1 = buildDihedra(factory, tolerance, center, axis1, halfAperture1);
  73.         final Region<Sphere2D> dihedra2 = buildDihedra(factory, tolerance, center, axis2, halfAperture2);
  74.         return (SphericalPolygonsSet) factory.intersection(dihedra1, dihedra2);
  75.     }

  76.     /** Build a dihedra.
  77.      * @param factory factory for regions
  78.      * @param tolerance tolerance below which points are considered equal
  79.      * @param center Direction of the FOV center, in spacecraft frame
  80.      * @param axis FOV dihedral axis, in spacecraft frame
  81.      * @param halfAperture FOV dihedral half aperture angle,
  82.      * must be less than π/2, i.e. full dihedra must be smaller then
  83.      * an hemisphere
  84.      * @return dihedra
  85.      */
  86.     private static Region<Sphere2D> buildDihedra(final RegionFactory<Sphere2D> factory,
  87.                                                  final double tolerance, final Vector3D center,
  88.                                                  final Vector3D axis, final double halfAperture) {
  89.         if (halfAperture > 0.5 * FastMath.PI) {
  90.             throw new OrekitException(LocalizedCoreFormats.OUT_OF_RANGE_SIMPLE,
  91.                                       halfAperture, 0.0, 0.5 * FastMath.PI);
  92.         }

  93.         final Rotation r = new Rotation(axis, halfAperture, RotationConvention.VECTOR_OPERATOR);
  94.         final Vector3D normalCenterPlane = Vector3D.crossProduct(axis, center);
  95.         final Vector3D normalSidePlus    = r.applyInverseTo(normalCenterPlane);
  96.         final Vector3D normalSideMinus   = r.applyTo(normalCenterPlane.negate());

  97.         return factory.intersection(new SphericalPolygonsSet(normalSidePlus,  tolerance),
  98.                                     new SphericalPolygonsSet(normalSideMinus, tolerance));

  99.     }

  100. }