Skip to content

Commit

Permalink
refactor: remove extra quaternion conversion methods (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwa2710 authored Dec 5, 2024
1 parent 298e57e commit fba3e5e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 50 deletions.
11 changes: 10 additions & 1 deletion docker/jupyter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN pip install --quiet "numpy~=2.0" "pandas" "plotly" "ipywidgets>=7.6" "ipympl
# Install JupyterLab extensions

RUN jupyter labextension install --no-build \
@jupyterlab/shortcuts-extension
@jupyterlab/shortcuts-extension

COPY ./shortcuts-extension /home/jovyan/.jupyter/lab/user-settings/@jupyterlab/shortcuts-extension

Expand All @@ -39,6 +39,15 @@ RUN git clone --branch v1 --single-branch --depth=1 https://github.com/open-spac

RUN chown -R ${NB_UID}:${NB_GID} ${OSTK_DATA_LOCAL_CACHE}

## Install libstdc++ including GLIBCXX_3.4.32 (For OSTk), can be removed when Ubuntu version >= 24.0 or debian >= 13.0

RUN apt-get update \
&& apt-get install -y software-properties-common \
&& add-apt-repository ppa:ubuntu-toolchain-r/test \
&& apt-get update \
&& apt-get install -y libstdc++6 \
&& rm -rf /var/lib/apt/lists/*

# Install Open Space Toolkit

RUN pip install open-space-toolkit-astrodynamics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ class AttitudeQuaternion : public CoordinateSubset
const Shared<const CoordinateBroker>& aCoordinateBrokerSPtr
) const override;

/// @brief Return a Quaternion from coordinates.
///
/// @param [in] coordinates coordinates vector
///
/// @return
static Quaternion coordinatesToQuaternion(const VectorXd& coordinates);

/// @brief Return coordinates from a Quaternion.
///
/// @param [in] quaterion quaternion
///
/// @return
static VectorXd quaterionToCoordinates(const Quaternion& quaternion);

/// @brief Return the default instance
///
/// @return The default instance
Expand Down
15 changes: 13 additions & 2 deletions src/OpenSpaceToolkit/Astrodynamics/Trajectory/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <OpenSpaceToolkit/Core/Error.hpp>
#include <OpenSpaceToolkit/Core/Utility.hpp>

#include <OpenSpaceToolkit/Mathematics/Geometry/3D/Transformation/Rotation/Quaternion.hpp>

#include <OpenSpaceToolkit/Astrodynamics/Trajectory/State.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AngularVelocity.hpp>
Expand All @@ -19,6 +21,8 @@ namespace trajectory

using ostk::core::type::Index;

using ostk::mathematics::geometry::d3::transformation::rotation::Quaternion;

using ostk::astrodynamics::trajectory::state::CoordinateSubset;
using ostk::astrodynamics::trajectory::state::coordinatesubset::AngularVelocity;
using ostk::astrodynamics::trajectory::state::coordinatesubset::AttitudeQuaternion;
Expand Down Expand Up @@ -135,7 +139,7 @@ State::State(
VectorXd coordinates(13);
coordinates.segment(0, 3) = aPosition.inUnit(Position::Unit::Meter).accessCoordinates();
coordinates.segment(3, 3) = aVelocity.inUnit(Velocity::Unit::MeterPerSecond).accessCoordinates();
coordinates.segment(6, 4) = AttitudeQuaternion::quaterionToCoordinates(anAttitude);
coordinates.segment(6, 4) = anAttitude.toVector(Quaternion::Format::XYZS);
coordinates.segment(10, 3) = anAngularVelocity;

static const Shared<CoordinateBroker> coordinatesBrokerSPtr = std::make_shared<CoordinateBroker>(CoordinateBroker(
Expand Down Expand Up @@ -403,7 +407,14 @@ Quaternion State::getAttitude() const
throw ostk::core::error::runtime::Undefined("State");
}

return AttitudeQuaternion::coordinatesToQuaternion(this->extractCoordinate(AttitudeQuaternion::Default()));
const VectorXd attitudeQuaternionCoordinates = this->extractCoordinate(AttitudeQuaternion::Default());

return Quaternion::XYZS(
attitudeQuaternionCoordinates[0],
attitudeQuaternionCoordinates[1],
attitudeQuaternionCoordinates[2],
attitudeQuaternionCoordinates[3]
);
}

Vector3d State::getAngularVelocity() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ VectorXd AngularVelocity::inFrame(
const VectorXd attitudeCoordinatesInFrame = this->attitudeQuaternionSPtr_->inFrame(
anInstant, aFullCoordinatesVector, fromFrame, toFrame, aCoordinateBrokerSPtr
);
const Quaternion quaternionInFrame =
AttitudeQuaternion::coordinatesToQuaternion(attitudeCoordinatesInFrame).toNormalized();
const Quaternion quaternionInFrame = Quaternion::XYZS(
attitudeCoordinatesInFrame[0],
attitudeCoordinatesInFrame[1],
attitudeCoordinatesInFrame[2],
attitudeCoordinatesInFrame[3]
)
.toNormalized();

const Transform transform = fromFrame->getTransformTo(toFrame, anInstant);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,13 @@ VectorXd AttitudeQuaternion::inFrame(
{
const VectorXd coordinates = aCoordinateBrokerSPtr->extractCoordinate(aFullCoordinatesVector, *this);

const Quaternion quaternion = coordinatesToQuaternion(coordinates);
const Quaternion quaternion = Quaternion::XYZS(coordinates[0], coordinates[1], coordinates[2], coordinates[3]);

const Transform transform = fromFrame->getTransformTo(toFrame, anInstant);

const Quaternion quaternionInFrame = quaternion * transform.getOrientation().toConjugate();

return quaterionToCoordinates(quaternionInFrame);
}

Quaternion AttitudeQuaternion::coordinatesToQuaternion(const VectorXd& coordinates)
{
return {coordinates(0), coordinates(1), coordinates(2), coordinates(3), Quaternion::Format::XYZS};
}

VectorXd AttitudeQuaternion::quaterionToCoordinates(const Quaternion& quaternion)
{
VectorXd coordinates(4);
coordinates << quaternion.x(), quaternion.y(), quaternion.z(), quaternion.s();

return coordinates;
return quaternionInFrame.toVector(Quaternion::Format::XYZS);
}

Shared<const AttitudeQuaternion> AttitudeQuaternion::Default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,6 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_State_CoordinateSubset_Attitude
}
}

TEST_F(
OpenSpaceToolkit_Astrodynamics_Trajectory_State_CoordinateSubset_AttitudeQuaternion, ConversionToAndFromQuaternion
)
{
{
VectorXd coordinates(4);
coordinates << 0.0, 0.0, 0.0, 1.0;

const Quaternion quaternion = AttitudeQuaternion::coordinatesToQuaternion(coordinates);

const VectorXd roundTripCoordinates = AttitudeQuaternion::quaterionToCoordinates(quaternion);

EXPECT_EQ(coordinates, roundTripCoordinates);
}
}

TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_State_CoordinateSubset_AttitudeQuaternion, Default)
{
{
Expand Down

0 comments on commit fba3e5e

Please sign in to comment.