1   /* Copyright 2022-2025 Luc Maisonobe
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.forces;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.hipparchus.util.FastMath;
23  import org.hipparchus.util.Precision;
24  import org.orekit.propagation.FieldSpacecraftState;
25  import org.orekit.propagation.SpacecraftState;
26  import org.orekit.utils.ExtendedPositionProvider;
27  
28  /** Class representing one panel of a satellite, roughly pointing towards some target.
29   * <p>
30   * It is mainly used to represent a rotating solar array that points towards the Sun.
31   * </p>
32   * <p>
33   * The panel rotation with respect to satellite body is the best pointing orientation
34   * achievable when the rotation axix is fixed by body attitude. Target is therefore
35   * always exactly in meridian plane defined by rotation axis and panel normal vector.
36   * </p>
37   * <p>
38   * These panels are considered to be always {@link #isDoubleSided() double-sided}.
39   * </p>
40   *
41   * @author Luc Maisonobe
42   * @since 3.0
43   */
44  public class PointingPanel extends Panel {
45  
46      /** Rotation axis. */
47      private final Vector3D rotationAxis;
48  
49      /** Target towards which the panel will point. */
50      private final ExtendedPositionProvider target;
51  
52      /** Simple constructor.
53       * <p>
54       * As the sum of absorption coefficient, specular reflection coefficient and
55       * diffuse reflection coefficient is exactly 1, only the first two coefficients
56       * are needed here, the third one is deduced from the other ones.
57       * </p>
58       * <p>
59       * The panel is considered to rotate about one axis in order to make its normal
60       * point as close as possible to the target. It means the target will always be
61       * in the plane defined by the rotation axis and the panel normal.
62       * </p>
63       * @param rotationAxis rotation axis of the panel
64       * @param target target towards which the panel will point (the Sun for a solar array)
65       * @param area panel area in m²
66       * @param drag drag coefficient
67       * @param liftRatio drag lift ratio (proportion between 0 and 1 of atmosphere modecules
68       * that will experience specular reflection when hitting spacecraft instead
69       * of experiencing diffuse reflection, hence producing lift)
70       * @param absorption radiation pressure absorption coefficient (between 0 and 1)
71       * @param reflection radiation pressure specular reflection coefficient (between 0 and 1)
72       */
73      public PointingPanel(final Vector3D rotationAxis, final ExtendedPositionProvider target,
74                           final double area,
75                           final double drag, final double liftRatio,
76                           final double absorption, final double reflection) {
77          super(area, true, drag, liftRatio, absorption, reflection);
78          this.rotationAxis = rotationAxis.normalize();
79          this.target       = target;
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public Vector3D getNormal(final SpacecraftState state) {
85  
86          // compute orientation for best pointing
87          final Vector3D targetInert = target.getPosition(state.getDate(), state.getFrame()).
88                                       subtract(state.getPosition()).normalize();
89          final Vector3D targetSpacecraft = state.getAttitude().getRotation().applyTo(targetInert);
90          final double d = Vector3D.dotProduct(targetSpacecraft, rotationAxis);
91          final double f = 1 - d * d;
92          if (f < Precision.EPSILON) {
93              // extremely rare case: the target is along panel rotation axis
94              // (there will not be much output power if it is a solar array…)
95              // we set up an arbitrary normal
96              return rotationAxis.orthogonal();
97          }
98  
99          final double s = 1.0 / FastMath.sqrt(f);
100         return new Vector3D(s, targetSpacecraft, -s * d, rotationAxis);
101 
102     }
103 
104     /** {@inheritDoc} */
105     @Override
106     public <T extends CalculusFieldElement<T>> FieldVector3D<T> getNormal(final FieldSpacecraftState<T> state) {
107         // compute orientation for best pointing
108         final FieldVector3D<T> targetInert = target.getPosition(state.getDate(), state.getFrame()).
109                                              subtract(state.getPosition()).normalize();
110         final FieldVector3D<T> targetSpacecraft = state.getAttitude().getRotation().applyTo(targetInert);
111         final T d = FieldVector3D.dotProduct(targetSpacecraft, rotationAxis);
112         final T f = d.multiply(d).subtract(1).negate();
113         if (f.getReal() < Precision.EPSILON) {
114             // extremely rare case: the target is along panel rotation axis
115             // (there will not be much output power if it is a solar array…)
116             // we set up an arbitrary normal
117             return new FieldVector3D<>(f.getField(), rotationAxis.orthogonal());
118         }
119 
120         final T s = f.sqrt().reciprocal();
121         return new FieldVector3D<>(s, targetSpacecraft,
122                                    s.multiply(d).negate(), new FieldVector3D<>(state.getDate().getField(), rotationAxis));
123     }
124 
125 }