[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orekit Users] Angle between satellite and a point




serkan dural <serkandural@yahoo.com> a écrit :

Hello,

Hi Serkan,


I need to calculate angle (roll and pitch) of a satellite in orbit and a point on earth. What is the best way to do it in orekit ?

If what you want to do is compute these two angles throughout some
propagation time range, the best way is to set the propagator to
master mode and perform the computation in a step handler that
will be called automatically during the propagation. When the step
handler will be called you will have the current state of the spacecraft,
and will be able to compute the angles.

So here is an example of what you can do. Of course, you can adapt this
example to you more specific needs. This example is split in two parts,
first the global setup that you must put in you main program and that
instantiate and registers the step handler, and then the step handler
itself. Beware that I write this example directly in the main, I did
not check it thoroughsly with a compiler, so the example may have some
syntax errors or some missing features, you may need to correct these
glitches by yourself. The example is intended as a guide only, not as
a complete solution.


  ---- global setup ---
  Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING,
                                                itrf);
  GeodeticPoint target = new GeodeticPoint(latitude, longitude, altitude);
  Frame eme2000 = FramesFactory.getEME2000();

  double step = 60.0;
  Propagator propagator = new KeplerianPropagator(null);
  propagator.setAttitudeProvider(new LofOffset(eme2000, LOFType.VVLH));
  propagator.setMasterMode(step, new PitchRollLogger(earth, target));

  propagator.propagate(endDate);
  ---- global setup ---


  ---- step handler ---

private static class PitchRollLogger implements OrekitFixedStepHandler {

  /** Earth frame. */
  private final Frame earthFrame;

  /** Target point on earth. */
  private final Vector3D target;

  /** Simple constructor.
   * @param earth Earth model
   * @param target target point on Earth
   */
public PitchRollLogger(final OneAxisEllipsoid earth, final GeodeticPoint target) {

    this.earthFrame = earth.getBodyFrame();

    // convert geodetic point to Cartesian coordinates
    // this avoid doing the computation on each step
    this.target = earth.transform(target);

  }

  /** {@inheritDoc} */
  @Override
  public void init(final SpacecraftState s0, final AbsoluteDate t) {
  }

  /** {@inheritDoc} */
  @Override
public void handleStep(final SpacecraftState currentState, final boolean isLast)
    throws PropagationException {
    try {

      // get the transform from Earth frame to inertial frame
Transform earthToInert = earthFrame.getTransformTo(currentState.getFrame(), currentState.getDate());

      // get the transform from inertial frame to spacecraft
      // this takes into account position, velocity, attitude ...
      Transform inertToSpacecraft = currentState.toTransform();

      // combine the two transforms
      Transform earthToSpacecraft =
                      new Transform(currentState.getDate(),
                                    earthToInert,
                                    inertToSpacecraft);

      // compute target point coordinates in spacecraft frame
      Vector3D targetInScFrame = earthToSpacecraft.transformPosition(target);

      // compute the angles, assuming the attitude is such that roll axis
      // is X, it is applied first, pitch axis is Y and applied after roll,
      // and zero roll, zero pitch corresponds to the +Z axis, and assuming
      // some arbitrary sign conventions for the angles
      // you may need to adjust these expressions to your exact conventions
double roll = FastMath.atan2(-targetInScFrame.getY(), targetInScFrame.getZ()); double pitch = 0.5 * FastMath.PI - Vector3D.angle(targetInScFrame, Vector3D.PLUS_I);

      System.out.format(Locale.US, "%s %9.4f %9.4f%n",
                        currentState.getDate(),
                        FastMath.toDegrees(roll),
                        FastMath.toDegrees(pitch));

    } catch (OrekitException oe) {
      // convert OrekitException to PropagationException
      throw new PropagationException(oe);
    }

  }

}
  ---- step handler ---


Thanks in advance...

Hope this helps,
Luc