Skip to content
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
6 changes: 3 additions & 3 deletions src/aliceVision/geometry/lie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ inline Eigen::Vector3d logm(const Eigen::Matrix3d& R)
Eigen::Matrix3d S = R + R.transpose() + (1.0 - R.trace()) * Eigen::Matrix3d::Identity();

Eigen::Vector3d signs;
// Use the sign of the biggest absolute values to define the rotation axis direction (its global sign)
if ( abs(p1) >= abs(p2) && abs(p1) >= abs(p3) )
// Use the largest diagonal entry to recover the axis signs, including at pi.
if (S(0, 0) >= S(1, 1) && S(0, 0) >= S(2, 2))
{
signs << SIGN(p1), SIGN(p1) * SIGN(S(1, 0)), SIGN(p1) * SIGN(S(2, 0));
}
else if ( abs(p2) >= abs(p1) && abs(p2) >= abs(p3) )
else if (S(1, 1) >= S(0, 0) && S(1, 1) >= S(2, 2))
{
signs << SIGN(p2) * SIGN(S(0, 1)), SIGN(p2), SIGN(p2) * SIGN(S(2, 1));
}
Expand Down
46 changes: 46 additions & 0 deletions src/aliceVision/geometry/lie_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,52 @@
#include <boost/test/tools/floating_point_comparison.hpp>
#include <aliceVision/unitTest.hpp>

#include <array>

BOOST_AUTO_TEST_CASE(SO3_logm_exact_half_turn)
{
using namespace Eigen;
using namespace aliceVision::SO3;

const std::array<Matrix3d, 7> rotations = {
(Matrix3d() << -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 0.0).finished(),
(Matrix3d() << -1.0, 0.0, 0.0, 0.0, -7.0 / 25.0, -24.0 / 25.0, 0.0, -24.0 / 25.0, 7.0 / 25.0).finished(),
(Matrix3d() << -7.0 / 25.0, -24.0 / 25.0, 0.0, -24.0 / 25.0, 7.0 / 25.0, 0.0, 0.0, 0.0, -1.0).finished(),
(Matrix3d() << 7.0 / 25.0, 0.0, -24.0 / 25.0, 0.0, -1.0, 0.0, -24.0 / 25.0, 0.0, -7.0 / 25.0).finished(),
(Matrix3d() << 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0).finished(),
(Matrix3d() << -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0).finished(),
(Matrix3d() << -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0).finished()};

for (const Matrix3d& rotation : rotations)
{
const Vector3d algebra = logm(rotation);
BOOST_CHECK_SMALL(algebra.norm() - M_PI, 1e-12);
BOOST_CHECK_SMALL((expm(algebra) - rotation).norm(), 1e-12);
}
}

BOOST_AUTO_TEST_CASE(SO3_logm_near_half_turn)
{
using namespace Eigen;
using namespace aliceVision::SO3;

const std::array<Vector3d, 3> axes = {Vector3d(-4.0, 0.0, 3.0), Vector3d(3.0, -4.0, 0.0), Vector3d(0.0, 3.0, -4.0)};

for (const Vector3d& axis : axes)
{
for (double offset : {2e-3, 1e-3, 1e-6, 1e-8})
{
for (double direction : {-1.0, 1.0})
{
const Vector3d expected = direction * (M_PI - offset) * axis.normalized();
const Matrix3d rotation = AngleAxisd(direction * (M_PI - offset), axis.normalized()).toRotationMatrix();
const Vector3d algebra = logm(rotation);
BOOST_CHECK_SMALL((algebra - expected).norm(), 1e-7);
BOOST_CHECK_SMALL((expm(algebra) - rotation).norm(), 1e-7);
}
}
}
}

BOOST_AUTO_TEST_CASE(PoseFilter_lie_conversions)
{
Expand Down
Loading