testQuaternion.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #include <gtsam/base/testLie.h>
21 
23 
24 using namespace std;
25 using namespace gtsam;
26 
27 typedef Quaternion Q; // Typedef
29 
30 //******************************************************************************
31 TEST(Quaternion , Concept) {
33  GTSAM_CONCEPT_ASSERT(IsManifold<Quaternion >);
35 }
36 
37 //******************************************************************************
38 TEST(Quaternion , Constructor) {
39  Q q(Eigen::AngleAxisd(1, Vector3(0, 0, 1)));
40 }
41 
42 //******************************************************************************
43 TEST(Quaternion , Logmap) {
44  Q q1(5e-06, 0, 0, 1), q2(-5e-06, 0, 0, -1);
48 }
49 
50 //******************************************************************************
51 TEST(Quaternion , Local) {
52  Vector3 z_axis(0, 0, 1);
53  Q q1(Eigen::AngleAxisd(0, z_axis));
54  Q q2(Eigen::AngleAxisd(0.1, z_axis));
55  QuaternionJacobian H1, H2;
56  Vector3 expected(0, 0, 0.1);
57  Vector3 actual = traits<Q>::Local(q1, q2, H1, H2);
58  EXPECT(assert_equal((Vector )expected, actual));
59 }
60 
61 //******************************************************************************
62 TEST(Quaternion , Retract) {
63  Vector3 z_axis(0, 0, 1);
64  Q q(Eigen::AngleAxisd(0, z_axis));
65  Q expected(Eigen::AngleAxisd(0.1, z_axis));
66  Vector3 v(0, 0, 0.1);
67  QuaternionJacobian Hq, Hv;
68  Q actual = traits<Q>::Retract(q, v, Hq, Hv);
69  EXPECT(actual.isApprox(expected));
70 }
71 
72 //******************************************************************************
73 TEST(Quaternion , Compose) {
74  Vector3 z_axis(0, 0, 1);
75  Q q1(Eigen::AngleAxisd(0.2, z_axis));
76  Q q2(Eigen::AngleAxisd(0.1, z_axis));
77 
78  Q expected = q1 * q2;
79  Q actual = traits<Q>::Compose(q1, q2);
81 }
82 
83 //******************************************************************************
85  Vector3 z_axis(0, 0, 1);
86  Q q1(Eigen::AngleAxisd(0.2, z_axis));
87  Q q2(Eigen::AngleAxisd(0.1, z_axis));
88 
89  Q expected = q1.inverse() * q2;
90  Q actual = traits<Q>::Between(q1, q2);
92 }
93 
94 //******************************************************************************
96  Vector3 z_axis(0, 0, 1);
97  Q q1(Eigen::AngleAxisd(0.1, z_axis));
98  Q expected(Eigen::AngleAxisd(-0.1, z_axis));
99 
100  Q actual = traits<Q>::Inverse(q1);
102 }
103 
104 //******************************************************************************
105 namespace {
106 Vector3 Q_z_axis(0, 0, 1);
107 Q id(Eigen::AngleAxisd(0, Q_z_axis));
108 Q R1(Eigen::AngleAxisd(1, Q_z_axis));
109 Q R2(Eigen::AngleAxisd(2, Vector3(0, 1, 0)));
110 } // namespace
111 
112 //******************************************************************************
113 TEST(Quaternion, Invariants) {
114  EXPECT(check_group_invariants(id, id));
115  EXPECT(check_group_invariants(id, R1));
116  EXPECT(check_group_invariants(R2, id));
117  EXPECT(check_group_invariants(R2, R1));
118 
119  EXPECT(check_manifold_invariants(id, id));
120  EXPECT(check_manifold_invariants(id, R1));
121  EXPECT(check_manifold_invariants(R2, id));
122  EXPECT(check_manifold_invariants(R2, R1));
123 }
124 
125 //******************************************************************************
126 TEST(Quaternion, LieGroupDerivatives) {
131 }
132 
133 //******************************************************************************
134 TEST(Quaternion, ChartDerivatives) {
135  CHECK_CHART_DERIVATIVES(id, id);
139 }
140 
141 //******************************************************************************
142 int main() {
143  TestResult tr;
144  return TestRegistry::runAllTests(tr);
145 }
146 //******************************************************************************
147 
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
Eigen::AngleAxis
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
Definition: ForwardDeclarations.h:290
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:43
testLie.h
gtsam::IsGroup
Definition: Group.h:42
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
Q
Quaternion Q
Definition: testQuaternion.cpp:27
so3::R1
SO3 R1
Definition: testShonanFactor.cpp:41
id
static const Similarity3 id
Definition: testSimilarity3.cpp:44
numericalDerivative.h
Some functions to compute numerical derivatives.
main
int main()
Definition: testQuaternion.cpp:142
Eigen::numext::q
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:1984
gtsam::IsLieGroup
Definition: Lie.h:260
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
CHECK_LIE_GROUP_DERIVATIVES
#define CHECK_LIE_GROUP_DERIVATIVES(t1, t2)
Definition: testLie.h:82
TestResult
Definition: TestResult.h:26
Between
BetweenFactor< Rot3 > Between
Definition: testRot3Optimization.cpp:31
Eigen::Quaternion
The quaternion class used to represent 3D orientations and rotations.
Definition: ForwardDeclarations.h:293
so3::R2
SO3 R2
Definition: testShonanFactor.cpp:43
gtsam
traits
Definition: SFMdata.h:40
gtsam::traits
Definition: Group.h:36
std
Definition: BFloat16.h:88
Quaternion.h
Lie Group wrapper for Eigen Quaternions.
v2
Vector v2
Definition: testSerializationBase.cpp:39
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Inverse
Definition: Inverse.java:13
GTSAM_CONCEPT_ASSERT
#define GTSAM_CONCEPT_ASSERT(concept)
Definition: base/concepts.h:22
CHECK_CHART_DERIVATIVES
#define CHECK_CHART_DERIVATIVES(t1, t2)
Definition: testLie.h:85
v1
Vector v1
Definition: testSerializationBase.cpp:38
QuaternionJacobian
traits< Q >::ChartJacobian QuaternionJacobian
Definition: testQuaternion.cpp:28
TEST
TEST(Quaternion, Concept)
Definition: testQuaternion.cpp:31
gtsam::BetweenFactor
Definition: BetweenFactor.h:40


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:08:20