Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
Simox
Commits
9ac24104
Commit
9ac24104
authored
6 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Added tests for Orthogonolize()
parent
9bd68e11
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
VirtualRobot/tests/MathHelpersTest.cpp
+96
-0
96 additions, 0 deletions
VirtualRobot/tests/MathHelpersTest.cpp
with
96 additions
and
0 deletions
VirtualRobot/tests/MathHelpersTest.cpp
+
96
−
0
View file @
9ac24104
...
...
@@ -187,3 +187,99 @@ BOOST_AUTO_TEST_CASE(test_toPose_matrix_and_rotation_matrix)
BOOST_AUTO_TEST_SUITE_END
()
struct
OrthogonolizeFixture
{
void
test
(
double
angle
,
const
Vector3d
&
axis
,
float
noiseAmpl
,
float
precAngularDist
);
Eigen
::
Matrix3f
test
(
Matrix3f
matrix
,
float
noiseAmpl
);
template
<
typename
Distribution
>
static
Eigen
::
Matrix3f
Random
(
Distribution
&
distrib
)
{
static
std
::
default_random_engine
gen
(
42
);
return
Eigen
::
Matrix3f
::
NullaryExpr
([
&
](
int
)
{
return
distrib
(
gen
);
});
}
};
void
OrthogonolizeFixture
::
test
(
double
angle
,
const
Vector3d
&
axis
,
float
noiseAmpl
,
float
precAngularDist
)
{
// construct matrix with double to avoid rounding errors
Eigen
::
AngleAxisd
rot
(
angle
,
axis
);
Eigen
::
Quaterniond
quat
(
rot
);
Eigen
::
Matrix3f
matrix
=
quat
.
toRotationMatrix
().
cast
<
float
>
();
Eigen
::
Matrix3f
orth
=
test
(
matrix
,
noiseAmpl
);
Quaternionf
quatOrth
(
orth
);
BOOST_MESSAGE
(
"Angular distance: "
<<
quatOrth
.
angularDistance
(
quat
.
cast
<
float
>
()));
BOOST_CHECK_LE
(
quatOrth
.
angularDistance
(
quat
.
cast
<
float
>
()),
precAngularDist
);
}
Matrix3f
OrthogonolizeFixture
::
test
(
Matrix3f
matrix
,
float
noiseAmpl
)
{
static
const
float
PREC_ORTHOGONAL
=
1e-6
f
;
BOOST_MESSAGE
(
"Rotation matrix:
\n
"
<<
matrix
);
BOOST_CHECK
(
math
::
Helpers
::
IsMatrixOrthogonal
(
matrix
,
PREC_ORTHOGONAL
));
// add noise (random coeffs are in [-1, 1])
std
::
normal_distribution
<
float
>
distrib
(
0
,
noiseAmpl
);
matrix
+=
noiseAmpl
*
this
->
Random
(
distrib
);
BOOST_MESSAGE
(
"Rotation matrix with noise:
\n
"
<<
matrix
);
if
(
noiseAmpl
>
0
)
{
BOOST_CHECK
(
!
math
::
Helpers
::
IsMatrixOrthogonal
(
matrix
,
PREC_ORTHOGONAL
));
}
Eigen
::
Matrix3f
orth
=
math
::
Helpers
::
Orthogonalize
(
matrix
);
BOOST_MESSAGE
(
"Orthogonalized:
\n
"
<<
orth
);
BOOST_CHECK
(
math
::
Helpers
::
IsMatrixOrthogonal
(
orth
,
PREC_ORTHOGONAL
));
BOOST_MESSAGE
(
"Q * Q.T: (should be Identitiy)
\n
"
<<
(
orth
*
orth
.
transpose
()));
return
orth
;
}
BOOST_FIXTURE_TEST_SUITE
(
Orthogonolization
,
OrthogonolizeFixture
)
BOOST_AUTO_TEST_CASE
(
test_orthogonalize_zero_rotation
)
{
test
(
Eigen
::
Matrix3f
::
Identity
(),
0
);
test
(
Eigen
::
Matrix3f
::
Identity
(),
0.1
f
);
test
(
0
,
Eigen
::
Vector3d
::
UnitX
(),
0.0
f
,
0.0
f
);
test
(
0
,
Eigen
::
Vector3d
::
UnitX
(),
1e-3
f
,
1e-3
f
);
}
BOOST_AUTO_TEST_CASE
(
test_orthogonalize_aligned_axis
)
{
test
(
M_PI
/
2
,
Eigen
::
Vector3d
::
UnitX
(),
1e-3
f
,
1e-3
f
);
test
(
M_PI
/
2
,
Eigen
::
Vector3d
::
UnitX
(),
0.1
f
,
0.2
f
);
test
(
.75
*
M_PI
,
Eigen
::
Vector3d
::
UnitZ
(),
1e-3
f
,
1e-3
f
);
test
(
.75
*
M_PI
,
Eigen
::
Vector3d
::
UnitZ
(),
0.1
f
,
0.2
f
);
test
(
M_PI
,
Eigen
::
Vector3d
::
UnitY
(),
1e-3
f
,
1e-3
f
);
test
(
M_PI
,
Eigen
::
Vector3d
::
UnitY
(),
0.1
f
,
0.2
f
);
}
BOOST_AUTO_TEST_CASE
(
test_orthogonalize_arbitrary_rotation
)
{
test
(
2.3
,
Eigen
::
Vector3d
(
0.3
,
1.
,
-
.5
).
normalized
(),
1e-3
f
,
1e-3
f
);
test
(
2.3
,
Eigen
::
Vector3d
(
0.3
,
1.
,
-
.5
).
normalized
(),
0.1
f
,
0.2
f
);
test
(
1.02
,
Eigen
::
Vector3d
(
-
2
,
.3
,
-
.25
).
normalized
(),
1e-3
f
,
1e-3
f
);
test
(
1.02
,
Eigen
::
Vector3d
(
-
3
,
2
,
-
10
).
normalized
(),
0.1
f
,
0.2
f
);
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment