Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Matrix6 class #455

Merged
merged 11 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions eigen3/include/ignition/math/eigen3/Conversions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <Eigen/Geometry>
#include <ignition/math/AxisAlignedBox.hh>
#include <ignition/math/Matrix3.hh>
#include <ignition/math/Matrix6.hh>
#include <ignition/math/Pose3.hh>
#include <ignition/math/Quaternion.hh>
#include <ignition/math/Vector3.hh>
Expand Down Expand Up @@ -66,6 +67,27 @@ namespace ignition
return matrix;
}

/// \brief Convert from ignition::math::Matrix6d to
/// Eigen::Matrix<Precision, 6, 6>.
/// \param[in] _m ignition::math::Matrix6d to convert.
/// \return The equivalent Eigen::Matrix<Precision, 6, 6>.
/// \tparam Precision Precision such as int, double or float.
template<typename Precision>
inline
Eigen::Matrix<Precision, 6, 6> convert(const Matrix6<Precision> &_m)
{
Eigen::Matrix<Precision, 6, 6> matrix;
for (std::size_t i = 0; i < 6; ++i)
{
for (std::size_t j = 0; j < 6; ++j)
{
matrix(i, j) = _m(i, j);
}
}

return matrix;
}

/// \brief Convert ignition::math::Quaterniond to Eigen::Quaterniond.
/// \param[in] _q ignition::math::Quaterniond to convert.
/// \return The equivalent Eigen::Quaterniond.
Expand Down Expand Up @@ -135,6 +157,27 @@ namespace ignition
return matrix;
}

/// \brief Convert Eigen::Matrix<Precision, 6, 6> to
/// ignition::math::Matrix6d.
/// \param[in] _m Eigen::Matrix<Precision, 6, 6> to convert.
/// \return The equivalent ignition::math::Matrix6d.
/// \tparam Precision Precision such as int, double or float.
template<typename Precision>
inline
Matrix6<Precision> convert(const Eigen::Matrix<Precision, 6, 6> &_m)
{
Matrix6<Precision> matrix;
for (std::size_t i = 0; i < 6; ++i)
{
for (std::size_t j = 0; j < 6; ++j)
{
matrix(i, j) = _m(i, j);
}
}

return matrix;
}

/// \brief Convert Eigen::Quaterniond to ignition::math::Quaterniond.
/// \param[in] _q Eigen::Quaterniond to convert.
/// \return The equivalent ignition::math::Quaterniond.
Expand Down
40 changes: 40 additions & 0 deletions eigen3/src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,46 @@ TEST(EigenConversions, ConvertMatrix3)
}
}

/////////////////////////////////////////////////
/// Check Matrix6 conversions
TEST(EigenConversions, ConvertMatrix6)
{
{
ignition::math::Matrix6d iMat, iMat2;
auto eMat = ignition::math::eigen3::convert(iMat);
for (std::size_t i = 0; i < 6; ++i)
{
for (std::size_t j = 0; j < 6; ++j)
{
EXPECT_DOUBLE_EQ(0.0, eMat(i, j));
}
}
iMat2 = ignition::math::eigen3::convert(eMat);
EXPECT_EQ(iMat, iMat2);
}

{
ignition::math::Matrix6d iMat(
0.0, 1.0, 2.0, 3.0, 4.0, 5.0,
6.0, 7.0, 8.0, 9.0, 10.0, 11.0,
12.0, 13.0, 14.0, 15.0, 16.0, 17.0,
18.0, 19.0, 20.0, 21.0, 22.0, 23.0,
24.0, 25.0, 26.0, 27.0, 28.0, 29.0,
30.0, 31.0, 32.0, 33.0, 34.0, 35.0);
ignition::math::Matrix6d iMat2;
auto eMat = ignition::math::eigen3::convert(iMat);
for (std::size_t i = 0; i < 6; ++i)
{
for (std::size_t j = 0; j < 6; ++j)
{
EXPECT_DOUBLE_EQ(iMat(i, j), eMat(i, j));
}
}
iMat2 = ignition::math::eigen3::convert(eMat);
EXPECT_EQ(iMat, iMat2);
}
}

/////////////////////////////////////////////////
/// Check Pose conversions
TEST(EigenConversions, ConvertPose3)
Expand Down
Loading