1 /* Copyright 2002-2024 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
19 import org.hipparchus.exception.LocalizedCoreFormats;
20 import org.hipparchus.geometry.euclidean.threed.Rotation;
21 import org.hipparchus.geometry.euclidean.threed.RotationConvention;
22 import org.hipparchus.geometry.euclidean.threed.Vector3D;
23 import org.hipparchus.geometry.partitioning.Region;
24 import org.hipparchus.geometry.partitioning.RegionFactory;
25 import org.hipparchus.geometry.spherical.twod.Sphere2D;
26 import org.hipparchus.geometry.spherical.twod.SphericalPolygonsSet;
27 import org.hipparchus.util.FastMath;
28 import org.orekit.errors.OrekitException;
29
30 /** Class representing a spacecraft sensor Field Of View with dihedral shape (i.e. rectangular shape).
31 * @author Luc Maisonobe
32 * @since 10.1
33 */
34 public class DoubleDihedraFieldOfView extends PolygonalFieldOfView {
35
36 /** Build a Field Of View with dihedral shape (i.e. rectangular shape).
37 * @param center Direction of the FOV center, in spacecraft frame
38 * @param axis1 FOV dihedral axis 1, in spacecraft frame
39 * @param halfAperture1 FOV dihedral half aperture angle 1,
40 * must be less than π/2, i.e. full dihedra must be smaller then
41 * an hemisphere
42 * @param axis2 FOV dihedral axis 2, in spacecraft frame
43 * @param halfAperture2 FOV dihedral half aperture angle 2,
44 * must be less than π/2, i.e. full dihedra must be smaller then
45 * an hemisphere
46 * @param margin angular margin to apply to the zone (if positive,
47 * points outside of the raw FoV but close enough to the boundary are
48 * considered visible; if negative, points inside of the raw FoV
49 * but close enough to the boundary are considered not visible)
50 */
51 public DoubleDihedraFieldOfView(final Vector3D center,
52 final Vector3D axis1, final double halfAperture1,
53 final Vector3D axis2, final double halfAperture2,
54 final double margin) {
55 super(createPolygon(center, axis1, halfAperture1, axis2, halfAperture2), margin);
56 }
57
58 /** Create polygon.
59 * @param center Direction of the FOV center, in spacecraft frame
60 * @param axis1 FOV dihedral axis 1, in spacecraft frame
61 * @param halfAperture1 FOV dihedral half aperture angle 1,
62 * must be less than π/2, i.e. full dihedra must be smaller then
63 * an hemisphere
64 * @param axis2 FOV dihedral axis 2, in spacecraft frame
65 * @param halfAperture2 FOV dihedral half aperture angle 2,
66 * must be less than π/2, i.e. full dihedra must be smaller then
67 * an hemisphere
68 * @return built polygon
69 */
70 private static SphericalPolygonsSet createPolygon(final Vector3D center,
71 final Vector3D axis1, final double halfAperture1,
72 final Vector3D axis2, final double halfAperture2) {
73 final RegionFactory<Sphere2D> factory = new RegionFactory<Sphere2D>();
74 final double tolerance = FastMath.max(FastMath.ulp(2.0 * FastMath.PI),
75 1.0e-12 * FastMath.max(halfAperture1, halfAperture2));
76 final Region<Sphere2D> dihedra1 = buildDihedra(factory, tolerance, center, axis1, halfAperture1);
77 final Region<Sphere2D> dihedra2 = buildDihedra(factory, tolerance, center, axis2, halfAperture2);
78 return (SphericalPolygonsSet) factory.intersection(dihedra1, dihedra2);
79 }
80
81 /** Build a dihedra.
82 * @param factory factory for regions
83 * @param tolerance tolerance below which points are considered equal
84 * @param center Direction of the FOV center, in spacecraft frame
85 * @param axis FOV dihedral axis, in spacecraft frame
86 * @param halfAperture FOV dihedral half aperture angle,
87 * must be less than π/2, i.e. full dihedra must be smaller then
88 * an hemisphere
89 * @return dihedra
90 */
91 private static Region<Sphere2D> buildDihedra(final RegionFactory<Sphere2D> factory,
92 final double tolerance, final Vector3D center,
93 final Vector3D axis, final double halfAperture) {
94 if (halfAperture > 0.5 * FastMath.PI) {
95 throw new OrekitException(LocalizedCoreFormats.OUT_OF_RANGE_SIMPLE,
96 halfAperture, 0.0, 0.5 * FastMath.PI);
97 }
98
99 final Rotation r = new Rotation(axis, halfAperture, RotationConvention.VECTOR_OPERATOR);
100 final Vector3D normalCenterPlane = Vector3D.crossProduct(axis, center);
101 final Vector3D normalSidePlus = r.applyInverseTo(normalCenterPlane);
102 final Vector3D normalSideMinus = r.applyTo(normalCenterPlane.negate());
103
104 return factory.intersection(new SphericalPolygonsSet(normalSidePlus, tolerance),
105 new SphericalPolygonsSet(normalSideMinus, tolerance));
106
107 }
108
109 }