testRot2.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 
18 #include <gtsam/geometry/Rot2.h>
19 #include <gtsam/base/Testable.h>
20 #include <gtsam/base/testLie.h>
22 
23 using namespace gtsam;
24 
27 
28 Rot2 R(Rot2::fromAngle(0.1));
29 Point2 P(0.2, 0.7);
30 
31 /* ************************************************************************* */
32 TEST( Rot2, constructors_and_angle)
33 {
34  double c=cos(0.1), s=sin(0.1);
35  DOUBLES_EQUAL(0.1,R.theta(),1e-9);
36  CHECK(assert_equal(R,Rot2(0.1)));
40 }
41 
42 /* ************************************************************************* */
43 TEST( Rot2, unit)
44 {
45  EXPECT(assert_equal(Point2(1.0, 0.0), Rot2::fromAngle(0).unit()));
46  EXPECT(assert_equal(Point2(0.0, 1.0), Rot2::fromAngle(M_PI/2.0).unit()));
47 }
48 
49 /* ************************************************************************* */
50 TEST( Rot2, transpose)
51 {
53  Matrix actual = R.transpose();
54  CHECK(assert_equal(expected,actual));
55 }
56 
57 /* ************************************************************************* */
59 {
62 
63  Matrix H1, H2;
64  (void) Rot2::fromAngle(1.0).compose(Rot2::fromAngle(2.0), H1, H2);
65  EXPECT(assert_equal(I_1x1, H1));
66  EXPECT(assert_equal(I_1x1, H2));
67 }
68 
69 /* ************************************************************************* */
71 {
74 
75  Matrix H1, H2;
76  (void) Rot2::fromAngle(1.0).between(Rot2::fromAngle(2.0), H1, H2);
77  EXPECT(assert_equal(-I_1x1, H1));
78  EXPECT(assert_equal(I_1x1, H2));
79 }
80 
81 /* ************************************************************************* */
83 {
84  CHECK(R.equals(R));
85  Rot2 zero;
86  CHECK(!R.equals(zero));
87 }
88 
89 /* ************************************************************************* */
90 TEST( Rot2, expmap)
91 {
92  Vector v = Z_1x1;
94 }
95 
96 /* ************************************************************************* */
98 {
99  Rot2 rot0(Rot2::fromAngle(M_PI/2.0));
101  Vector expected = (Vector(1) << M_PI/2.0).finished();
102  Vector actual = rot0.localCoordinates(rot);
103  CHECK(assert_equal(expected, actual));
104 }
105 
106 /* ************************************************************************* */
107 TEST(Rot2, HatAndVee) {
108  // Create a few test vectors
109  Vector1 v1 = (Vector1() << 1).finished();
110  Vector1 v2 = (Vector1() << 0.1).finished();
111  Vector1 v3 = (Vector1() << 0.0).finished();
112 
113  // Test that Vee(Hat(v)) == v for various inputs
117 
118  // Check the structure of the Lie Algebra element
119  Matrix2 expected;
120  expected << 0., -1., 1., 0.;
121 
123 }
124 
125 /* ************************************************************************* */
126 // rotate and derivatives
127 inline Point2 rotate_(const Rot2 & R, const Point2& p) {return R.rotate(p);}
129 {
130  Matrix H1, H2;
131  Point2 actual = R.rotate(P, H1, H2);
132  CHECK(assert_equal(actual,R*P));
133  Matrix numerical1 = numericalDerivative21(rotate_, R, P);
134  CHECK(assert_equal(numerical1,H1));
135  Matrix numerical2 = numericalDerivative22(rotate_, R, P);
136  CHECK(assert_equal(numerical2,H2));
137 }
138 
139 /* ************************************************************************* */
140 // unrotate and derivatives
141 inline Point2 unrotate_(const Rot2& R, const Point2& p) {return R.unrotate(p);}
143 {
144  Matrix H1, H2;
145  Point2 w = R * P, actual = R.unrotate(w, H1, H2);
146  CHECK(assert_equal(actual,P));
147  Matrix numerical1 = numericalDerivative21(unrotate_, R, w);
148  CHECK(assert_equal(numerical1,H1));
149  Matrix numerical2 = numericalDerivative22(unrotate_, R, w);
150  CHECK(assert_equal(numerical2,H2));
151 }
152 
153 /* ************************************************************************* */
155 TEST( Rot2, relativeBearing )
156 {
157  Point2 l1(1, 0), l2(1, 1);
158  Matrix expectedH, actualH;
159 
160  // establish relativeBearing is indeed zero
161  Rot2 actual1 = Rot2::relativeBearing(l1, actualH);
162  CHECK(assert_equal(Rot2(),actual1));
163 
164  // Check numerical derivative
166  CHECK(assert_equal(expectedH,actualH));
167 
168  // establish relativeBearing is indeed 45 degrees
169  Rot2 actual2 = Rot2::relativeBearing(l2, actualH);
170  CHECK(assert_equal(Rot2::fromAngle(M_PI/4.0),actual2));
171 
172  // Check numerical derivative
174  CHECK(assert_equal(expectedH,actualH));
175 }
176 
177 /* ************************************************************************* */
178 TEST(Rot2, vec) {
179  // Test the 'vec' method
180  Vector4 expected_vec = Eigen::Map<Vector4>(R.matrix().data());
181  Matrix41 actualH;
182  Vector4 actual_vec = R.vec(actualH);
183  EXPECT(assert_equal(expected_vec, actual_vec));
184 
185  // Verify Jacobian with numerical derivatives
186  std::function<Vector4(const Rot2&)> f = [](const Rot2& p) { return p.vec(); };
187  Matrix41 numericalH = numericalDerivative11<Vector4, Rot2>(f, R);
188  EXPECT(assert_equal(numericalH, actualH, 1e-9));
189 }
190 
191 //******************************************************************************
192 namespace {
193 Rot2 id;
194 Rot2 T1(0.1);
195 Rot2 T2(0.2);
196 } // namespace
197 
198 //******************************************************************************
199 TEST(Rot2, Invariants) {
200  EXPECT(check_group_invariants(id, id));
201  EXPECT(check_group_invariants(id, T1));
202  EXPECT(check_group_invariants(T2, id));
203  EXPECT(check_group_invariants(T2, T1));
204 
205  EXPECT(check_manifold_invariants(id, id));
206  EXPECT(check_manifold_invariants(id, T1));
207  EXPECT(check_manifold_invariants(T2, id));
208  EXPECT(check_manifold_invariants(T2, T1));
209 }
210 
211 //******************************************************************************
212 TEST(Rot2, LieGroupDerivatives) {
217 }
218 
219 //******************************************************************************
220 TEST(Rot2, ChartDerivatives) {
221  CHECK_CHART_DERIVATIVES(id, id);
225 }
226 
227 /* ************************************************************************* */
228 int main() {
229  TestResult tr;
230  return TestRegistry::runAllTests(tr);
231 }
232 /* ************************************************************************* */
233 
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
w
RowVector3d w
Definition: Matrix_resize_int.cpp:3
gtsam::LieGroup::between
Class between(const Class &g) const
Definition: Lie.h:52
gtsam::logmap
gtsam::Expression< typename gtsam::traits< T >::TangentVector > logmap(const gtsam::Expression< T > &x1, const gtsam::Expression< T > &x2)
logmap
Definition: slam/expressions.h:196
gtsam::Vector1
Eigen::Matrix< double, 1, 1 > Vector1
Definition: Vector.h:42
gtsam::between
Expression< T > between(const Expression< T > &t1, const Expression< T > &t2)
Definition: nonlinear/expressions.h:17
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::Rot2::unrotate
Point2 unrotate(const Point2 &p, OptionalJacobian< 2, 1 > H1={}, OptionalJacobian< 2, 2 > H2={}) const
Definition: Rot2.cpp:125
GTSAM_CONCEPT_TESTABLE_INST
#define GTSAM_CONCEPT_TESTABLE_INST(T)
Definition: Testable.h:176
Testable.h
Concept check for values that can be used in unit tests.
ceres::sin
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:439
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
l2
gtsam::Key l2
Definition: testLinearContainerFactor.cpp:24
TestHarness.h
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::Rot2::fromCosSin
static Rot2 fromCosSin(double c, double s)
Named constructor from cos(theta),sin(theta) pair.
Definition: Rot2.cpp:27
gtsam::LieGroup::compose
Class compose(const Class &g) const
Definition: Lie.h:48
gtsam::numericalDerivative11
internal::FixedSizeMatrix< Y, X >::type numericalDerivative11(std::function< Y(const X &)> h, const X &x, double delta=1e-5)
New-style numerical derivatives using manifold_traits.
Definition: numericalDerivative.h:110
gtsam::Rot2::relativeBearing
static Rot2 relativeBearing(const Point2 &d, OptionalJacobian< 1, 2 > H={})
Definition: Rot2.cpp:134
gtsam::Rot2::atan2
static Rot2 atan2(double y, double x)
Definition: Rot2.cpp:33
gtsam::Rot2::theta
double theta() const
Definition: Rot2.h:197
gtsam::numericalDerivative22
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(std::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
Definition: numericalDerivative.h:195
pt
static const Point3 pt(1.0, 2.0, 3.0)
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::Rot2::matrix
Matrix2 matrix() const
Definition: Rot2.cpp:100
testLie.h
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
rot
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
Definition: level1_real_impl.h:79
Rot2.h
2D rotation
ceres::cos
Jet< T, N > cos(const Jet< T, N > &f)
Definition: jet.h:426
gtsam::compose
Expression< T > compose(const Expression< T > &t1, const Expression< T > &t2)
Definition: nonlinear/expressions.h:23
gtsam::Rot2::fromAngle
static Rot2 fromAngle(double theta)
Named constructor from angle in radians.
Definition: Rot2.h:64
gtsam::Rot2::vec
Vector4 vec(OptionalJacobian< 4, 1 > H={}) const
Return vectorized SO(2) matrix in column order.
Definition: Rot2.cpp:161
id
static const Similarity3 id
Definition: testSimilarity3.cpp:44
gtsam::unrotate
Point3_ unrotate(const Rot3_ &x, const Point3_ &p)
Definition: slam/expressions.h:113
gtsam::rotate
Point3_ rotate(const Rot3_ &x, const Point3_ &p)
Definition: slam/expressions.h:101
gtsam::Rot2::equals
bool equals(const Rot2 &R, double tol=1e-9) const
Definition: Rot2.cpp:51
DOUBLES_EQUAL
#define DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:141
GTSAM_CONCEPT_LIE_INST
#define GTSAM_CONCEPT_LIE_INST(T)
Definition: Lie.h:410
main
int main()
Definition: testRot2.cpp:228
zero
EIGEN_DONT_INLINE Scalar zero()
Definition: svd_common.h:296
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:916
CHECK_LIE_GROUP_DERIVATIVES
#define CHECK_LIE_GROUP_DERIVATIVES(t1, t2)
Definition: testLie.h:82
gtsam::Point2
Vector2 Point2
Definition: Point2.h:32
T2
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
unrotate_
Point2 unrotate_(const Rot2 &R, const Point2 &p)
Definition: testRot2.cpp:141
gtsam::Rot2::transpose
Matrix2 transpose() const
Definition: Rot2.cpp:107
gtsam::LieGroup::localCoordinates
TangentVector localCoordinates(const Class &g) const
localCoordinates as required by manifold concept: finds tangent vector between *this and g
Definition: Lie.h:136
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
gtsam::equals
Definition: Testable.h:112
TestResult
Definition: TestResult.h:26
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
gtsam::Rot2::rotate
Point2 rotate(const Point2 &p, OptionalJacobian< 2, 1 > H1={}, OptionalJacobian< 2, 2 > H2={}) const
Definition: Rot2.cpp:115
gtsam::Rot2
Definition: Rot2.h:35
gtsam
traits
Definition: SFMdata.h:40
gtsam::TEST
TEST(SmartFactorBase, Pinhole)
Definition: testSmartFactorBase.cpp:38
gtsam::Rot2::Vee
static Vector1 Vee(const Matrix2 &X)
Vee maps from Lie algebra to tangent vector.
Definition: Rot2.cpp:93
CHECK
#define CHECK(condition)
Definition: Test.h:108
gtsam::numericalDerivative21
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative21(const std::function< Y(const X1 &, const X2 &)> &h, const X1 &x1, const X2 &x2, double delta=1e-5)
Definition: numericalDerivative.h:166
l1
gtsam::Key l1
Definition: testLinearContainerFactor.cpp:24
gtsam::Rot2::Hat
static Matrix2 Hat(const Vector1 &xi)
Hat maps from tangent vector to Lie algebra.
Definition: Rot2.cpp:85
p
float * p
Definition: Tutorial_Map_using.cpp:9
v2
Vector v2
Definition: testSerializationBase.cpp:39
relativeBearing_
Rot2 relativeBearing_(const Point2 &pt)
Definition: testRot2.cpp:154
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:41
gtsam::LieGroup::retract
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
Definition: Lie.h:131
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
v3
Vector v3
Definition: testSerializationBase.cpp:40
M_PI
#define M_PI
Definition: mconf.h:117
T1
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
gtsam::Rot2::inverse
Rot2 inverse() const
Definition: Rot2.h:116
CHECK_CHART_DERIVATIVES
#define CHECK_CHART_DERIVATIVES(t1, t2)
Definition: testLie.h:85
P
Point2 P(0.2, 0.7)
R
Rot2 R(Rot2::fromAngle(0.1))
v1
Vector v1
Definition: testSerializationBase.cpp:38
rotate_
Point2 rotate_(const Rot2 &R, const Point2 &p)
Definition: testRot2.cpp:127


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:07:39