From fba3e5eed67cb804f04815c5daf720002cbb3581 Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Thu, 5 Dec 2024 16:33:55 -0700 Subject: [PATCH] refactor: remove extra quaternion conversion methods (#469) --- docker/jupyter/Dockerfile | 11 ++++++++++- .../CoordinateSubset/AttitudeQuaternion.hpp | 14 -------------- .../Astrodynamics/Trajectory/State.cpp | 15 +++++++++++++-- .../State/CoordinateSubset/AngularVelocity.cpp | 9 +++++++-- .../CoordinateSubset/AttitudeQuaternion.cpp | 17 ++--------------- .../AttitudeQuaternion.test.cpp | 16 ---------------- 6 files changed, 32 insertions(+), 50 deletions(-) diff --git a/docker/jupyter/Dockerfile b/docker/jupyter/Dockerfile index 1afb9f0e6..6182042ea 100644 --- a/docker/jupyter/Dockerfile +++ b/docker/jupyter/Dockerfile @@ -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 @@ -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 diff --git a/include/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.hpp b/include/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.hpp index 6eba5e390..588d6ef38 100644 --- a/include/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.hpp +++ b/include/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.hpp @@ -68,20 +68,6 @@ class AttitudeQuaternion : public CoordinateSubset const Shared& 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 diff --git a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State.cpp b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State.cpp index 15af119da..9c324bd09 100644 --- a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State.cpp +++ b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include #include @@ -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; @@ -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 coordinatesBrokerSPtr = std::make_shared(CoordinateBroker( @@ -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 diff --git a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AngularVelocity.cpp b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AngularVelocity.cpp index 500b6b395..afb266737 100644 --- a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AngularVelocity.cpp +++ b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AngularVelocity.cpp @@ -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); diff --git a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.cpp b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.cpp index 6d730cb2b..8d29618ad 100644 --- a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.cpp +++ b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.cpp @@ -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 AttitudeQuaternion::Default() diff --git a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.test.cpp b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.test.cpp index 364493e19..62b316335 100644 --- a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.test.cpp +++ b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/State/CoordinateSubset/AttitudeQuaternion.test.cpp @@ -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) { {