Commit 4131a93d authored by Jesse Mapel's avatar Jesse Mapel Committed by GitHub
Browse files

Fixed constant rotations in Orientations (#350)

parent 84db83ad
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -62,8 +62,6 @@ namespace ale {

    PositionInterpolation interpMethod;

    Rotation const_rotation;

    States inst_pos;
    States sun_pos;

+0 −3
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ namespace ale {
      const std::vector<Rotation> &rotations,
      const std::vector<double> &times,
      const std::vector<Vec3d> &avs = std::vector<ale::Vec3d>(),
      const int refFrame = 1,
      const Rotation &constRot = Rotation(1, 0, 0, 0),
      const std::vector<int> const_frames = std::vector<int>(),
      const std::vector<int> time_dependent_frames = std::vector<int>()
@@ -40,7 +39,6 @@ namespace ale {
    std::vector<double> getTimes() const;
    std::vector<int> getConstantFrames() const;
    std::vector<int> getTimeDependentFrames() const;
    int getReferenceFrame() const;
    Rotation getConstantRotation() const;

    /**
@@ -89,7 +87,6 @@ namespace ale {
    std::vector<int> m_timeDepFrames;
    std::vector<int> m_constFrames;
    Rotation m_constRotation;
    int m_refFrame;
  };
}

+10 −10
Original line number Diff line number Diff line
@@ -8,12 +8,11 @@ namespace ale {
    const std::vector<Rotation> &rotations,
    const std::vector<double> &times,
    const std::vector<Vec3d> &avs,
    const int refFrame,
    const Rotation &const_rot,
    const std::vector<int> const_frames,
    const std::vector<int> time_dependent_frames
  ) :
    m_rotations(rotations), m_avs(avs), m_times(times), m_refFrame(refFrame), m_timeDepFrames(time_dependent_frames), m_constFrames(const_frames), m_constRotation(const_rot) {
    m_rotations(rotations), m_avs(avs), m_times(times), m_timeDepFrames(time_dependent_frames), m_constFrames(const_frames), m_constRotation(const_rot) {
    if (m_rotations.size() < 2 || m_times.size() < 2) {
      throw std::invalid_argument("There must be at least two rotations and times.");
    }
@@ -48,10 +47,6 @@ namespace ale {
    return m_constFrames;
  }

  int Orientations::getReferenceFrame() const {
    return m_refFrame;
  }

  Rotation Orientations::getConstantRotation() const {
    return m_constRotation;
  }
@@ -62,7 +57,7 @@ namespace ale {
  ) const {
    int interpIndex = interpolationIndex(m_times, time);
    double t = (time - m_times[interpIndex]) / (m_times[interpIndex + 1] - m_times[interpIndex]);
    return m_rotations[interpIndex].interpolate(m_rotations[interpIndex + 1], t, interpType);
    return m_constRotation * m_rotations[interpIndex].interpolate(m_rotations[interpIndex + 1], t, interpType);
  }


@@ -80,6 +75,9 @@ namespace ale {
    bool invert
  ) const {
    Rotation interpRot = interpolate(time, interpType);
    if (invert) {
      interpRot = interpRot.inverse();
    }
    return interpRot(vector);
  }

@@ -109,8 +107,10 @@ namespace ale {
    std::vector<Rotation> mergedRotations;
    std::vector<Vec3d> mergedAvs;
    for (double time: mergedTimes) {
      // interpolate includes the constant rotation, so invert it to undo that
      Rotation inverseConst = m_constRotation.inverse();
      Rotation rhsRot = rhs.interpolate(time);
      mergedRotations.push_back(interpolate(time)*rhsRot);
      mergedRotations.push_back(inverseConst*interpolate(time)*rhsRot);
      Vec3d combinedAv = rhsRot.inverse()(interpolateAV(time));
      Vec3d rhsAv = rhs.interpolateAV(time);
      combinedAv.x += rhsAv.x;
@@ -133,10 +133,10 @@ namespace ale {
      updatedRotations.push_back(m_rotations[i]*rhs);
    }

    Rotation inverse = rhs.inverse();
    Rotation inverseRhs = rhs.inverse();
    std::vector<Vec3d> updatedAvs;
    for (size_t i = 0; i < m_avs.size(); i++) {
      updatedAvs.push_back(inverse(m_avs[i]));
      updatedAvs.push_back(inverseRhs(m_avs[i]));
    }

    m_rotations = updatedRotations;
+2 −5
Original line number Diff line number Diff line
@@ -534,7 +534,6 @@ Orientations getInstrumentPointing(json isd) {
    std::vector<Rotation> rotations = getJsonQuatArray(pointing.at("quaternions"));
    std::vector<double> times = getJsonArray<double>(pointing.at("ephemeris_times"));
    std::vector<Vec3d> velocities = getJsonVec3dArray(pointing.at("angular_velocities"));
    int refFrame = pointing.at("reference_frame").get<int>();

    std::vector<int> constFrames;
    if (pointing.find("constant_frames") != pointing.end()){
@@ -553,7 +552,7 @@ Orientations getInstrumentPointing(json isd) {

    Rotation constRot(rotArray);

    Orientations orientation(rotations, times, velocities, refFrame, constRot, constFrames, timeDepFrames);
    Orientations orientation(rotations, times, velocities, constRot, constFrames, timeDepFrames);

    return orientation;

@@ -569,8 +568,6 @@ Orientations getBodyRotation(json isd) {
    std::vector<double> times = getJsonArray<double>(bodrot.at("ephemeris_times"));
    std::vector<Vec3d> velocities = getJsonVec3dArray(bodrot.at("angular_velocities"));

    int refFrame = bodrot.at("reference_frame").get<int>();

    std::vector<int> constFrames;
    if (bodrot.find("constant_frames") != bodrot.end()){
      constFrames  = getJsonArray<int>(bodrot.at("constant_frames"));
@@ -588,7 +585,7 @@ Orientations getBodyRotation(json isd) {

    Rotation constRot(rotArray);

    Orientations orientation(rotations, times, velocities, refFrame, constRot, constFrames, timeDepFrames);
    Orientations orientation(rotations, times, velocities, constRot, constFrames, timeDepFrames);
    return orientation;

  } catch (...) {
+0 −2
Original line number Diff line number Diff line
@@ -268,7 +268,6 @@ TEST(Isd, GetInstrumentPointing) {
  std::vector<int> timeDepFrames = instPointing.getTimeDependentFrames();

  ASSERT_EQ(rotations.size(), 2);
  ASSERT_EQ(instPointing.getReferenceFrame(), 2);
  ASSERT_EQ(instPointing.getTimes()[0], 300);
  ASSERT_EQ(instPointing.getTimes()[1], 600);

@@ -339,7 +338,6 @@ TEST(Isd, GetBodyRotation) {
  std::vector<int> timeDepFrames = bodyRot.getTimeDependentFrames();

  ASSERT_EQ(rotations.size(), 2);
  ASSERT_EQ(bodyRot.getReferenceFrame(), 2);
  ASSERT_EQ(bodyRot.getTimes()[0], 300);
  ASSERT_EQ(bodyRot.getTimes()[1], 600);

Loading