Sun angle calculation

Hi everyone,

I’m new to using Orekit, and it’s great to see such a helpful community!

I’m trying to compute the angle between the Sun and one of my spacecraft’s axes (which should be pointing toward the Sun).
For now, I’m using a Sun-pointing attitude law to verify my calculations, but the goal is to later replace it with an attitude sequence.

The issue is that even with the Sun-pointing law, I still get a non-zero angle during propagation — which shouldn’t happen given how the attitude law is defined.

The attitude law is defined with the following :

Sun_Pointing_law = CelestialBodyPointed(
    FramesFactory.getEME2000(),
    sun,
    Vector3D.MINUS_I,
    Vector3D.MINUS_K,
    Vector3D.MINUS_J,
)
propagator.setAttitudeProvider(Sun_Pointing_law)
final_state = propagator.propagate(
    initial_date, initial_date.shiftedBy(Propagation_duration)
)

The handler is defined as the following :

def Handler_for_sun_angle():
    class HandlerForDate(PythonOrekitFixedStepHandler):
        def init(self, so, t, step):
            super().__init__()
            self.data = {
                "absdates": [],
                "Sun_angle": [],
                "Beta_angle_with_Z_axis": [],
            }
            self.sun = PVCoordinatesProvider.cast_(CelestialBodyFactory.getSun())

          def handleStep(self, state):
              date = state.getDate()  
              sunPos = self.sun.getPosition(state.getDate(), state.getFrame())
              Sun_angle_rad = Vector3D.angle(sunPos, state.getPosition())
  
              sat_axis_inertial = state.getAttitude().getRotation().applyTo(Vector3D.MINUS_I)
              Beta_angle = Vector3D.angle(sat_axis_inertial, sunPos)
  
              Sun_angle_deg = math.degrees(Sun_angle_rad)
              self.data["Sun_angle"].append(Sun_angle_deg)
              Beta_angle_deg = math.degrees(Beta_angle)
              self.data["absdates"].append(absolute_to_datetime(date))
              self.data["Beta_angle_with_Z_axis"].append(Beta_angle_deg)              

Here is the angles I obtained :

The red plot is not constant=0 …

Please let me know if you have any ideas !

Thanks for the help you could provide me with !
Cheers

Your attitude configuration is to point the MINUS_K vector to the Sun, not the MINUS_I.
I agree the construction parameters for CelestialBodyPointed are confusing, maybe you should use AlignedAndConstrained with a PredefinedTarget.SUN target provider, it is easier to understand.

Also note that both attitude modes take parallax effect into account, so instead of using directly sunPos, which is the position of the Sun as seen from the frame origin, i.e. center of Earth, you should probably subtract satellite position to have the vector from satellite to Sun instead of from Earth to Sun.

1 Like