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)));
39  CHECK(assert_equal(R,Rot2::atan2(s*5,c*5)));
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 /* ************************************************************************* */
97 TEST(Rot2, logmap)
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 // rotate and derivatives
108 inline Point2 rotate_(const Rot2 & R, const Point2& p) {return R.rotate(p);}
110 {
111  Matrix H1, H2;
112  Point2 actual = R.rotate(P, H1, H2);
113  CHECK(assert_equal(actual,R*P));
114  Matrix numerical1 = numericalDerivative21(rotate_, R, P);
115  CHECK(assert_equal(numerical1,H1));
116  Matrix numerical2 = numericalDerivative22(rotate_, R, P);
117  CHECK(assert_equal(numerical2,H2));
118 }
119 
120 /* ************************************************************************* */
121 // unrotate and derivatives
122 inline Point2 unrotate_(const Rot2& R, const Point2& p) {return R.unrotate(p);}
124 {
125  Matrix H1, H2;
126  Point2 w = R * P, actual = R.unrotate(w, H1, H2);
127  CHECK(assert_equal(actual,P));
128  Matrix numerical1 = numericalDerivative21(unrotate_, R, w);
129  CHECK(assert_equal(numerical1,H1));
130  Matrix numerical2 = numericalDerivative22(unrotate_, R, w);
131  CHECK(assert_equal(numerical2,H2));
132 }
133 
134 /* ************************************************************************* */
135 inline Rot2 relativeBearing_(const Point2& pt) {return Rot2::relativeBearing(pt); }
136 TEST( Rot2, relativeBearing )
137 {
138  Point2 l1(1, 0), l2(1, 1);
139  Matrix expectedH, actualH;
140 
141  // establish relativeBearing is indeed zero
142  Rot2 actual1 = Rot2::relativeBearing(l1, actualH);
143  CHECK(assert_equal(Rot2(),actual1));
144 
145  // Check numerical derivative
147  CHECK(assert_equal(expectedH,actualH));
148 
149  // establish relativeBearing is indeed 45 degrees
150  Rot2 actual2 = Rot2::relativeBearing(l2, actualH);
151  CHECK(assert_equal(Rot2::fromAngle(M_PI/4.0),actual2));
152 
153  // Check numerical derivative
154  expectedH = numericalDerivative11(relativeBearing_, l2);
155  CHECK(assert_equal(expectedH,actualH));
156 }
157 
158 //******************************************************************************
159 Rot2 T1(0.1);
160 Rot2 T2(0.2);
161 
162 //******************************************************************************
163 TEST(Rot2 , Invariants) {
164  Rot2 id;
165 
166  EXPECT(check_group_invariants(id,id));
167  EXPECT(check_group_invariants(id,T1));
168  EXPECT(check_group_invariants(T2,id));
169  EXPECT(check_group_invariants(T2,T1));
170 
171  EXPECT(check_manifold_invariants(id,id));
172  EXPECT(check_manifold_invariants(id,T1));
173  EXPECT(check_manifold_invariants(T2,id));
174  EXPECT(check_manifold_invariants(T2,T1));
175 
176 }
177 
178 //******************************************************************************
179 TEST(Rot2 , LieGroupDerivatives) {
180  Rot2 id;
181 
186 
187 }
188 
189 //******************************************************************************
190 TEST(Rot2 , ChartDerivatives) {
191  Rot2 id;
192 
197 }
198 
199 /* ************************************************************************* */
200 int main() {
201  TestResult tr;
202  return TestRegistry::runAllTests(tr);
203 }
204 /* ************************************************************************* */
205 
Point3_ unrotate(const Rot3_ &x, const Point3_ &p)
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
#define CHECK(condition)
Definition: Test.h:109
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Point2 rotate(const Point2 &p, OptionalJacobian< 2, 1 > H1=boost::none, OptionalJacobian< 2, 2 > H2=boost::none) const
Definition: Rot2.cpp:104
bool equals(const Rot2 &R, double tol=1e-9) const
Definition: Rot2.cpp:55
Point2 rotate_(const Rot2 &R, const Point2 &p)
Definition: testRot2.cpp:108
Q id(Eigen::AngleAxisd(0, Q_z_axis))
Matrix expected
Definition: testMatrix.cpp:974
#define DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:142
Vector2 Point2
Definition: Point2.h:27
EIGEN_DONT_INLINE Scalar zero()
Definition: svd_common.h:271
ArrayXcf v
Definition: Cwise_arg.cpp:1
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
#define M_PI
Definition: main.h:78
Rot2 R(Rot2::fromAngle(0.1))
gtsam::Key l2
Rot2 T2(0.2)
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative21(const boost::function< Y(const X1 &, const X2 &)> &h, const X1 &x1, const X2 &x2, double delta=1e-5)
static const Point3 pt(1.0, 2.0, 3.0)
static Rot2 relativeBearing(const Point2 &d, OptionalJacobian< 1, 2 > H=boost::none)
Definition: Rot2.cpp:123
static Rot2 fromCosSin(double c, double s)
Named constructor from cos(theta),sin(theta) pair, will not normalize!
Definition: Rot2.cpp:27
#define GTSAM_CONCEPT_LIE_INST(T)
Definition: Lie.h:355
static Rot2 atan2(double y, double x)
Definition: Rot2.cpp:37
Point2 unrotate(const Point2 &p, OptionalJacobian< 2, 1 > H1=boost::none, OptionalJacobian< 2, 2 > H2=boost::none) const
Definition: Rot2.cpp:114
#define CHECK_LIE_GROUP_DERIVATIVES(t1, t2)
Definition: testLie.h:82
EIGEN_DEVICE_FUNC const CosReturnType cos() const
Class compose(const Class &g) const
Definition: Lie.h:47
Eigen::VectorXd Vector
Definition: Vector.h:38
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(boost::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
double theta() const
Definition: Rot2.h:183
Matrix2 transpose() const
Definition: Rot2.cpp:96
#define EXPECT(condition)
Definition: Test.h:151
Matrix2 matrix() const
Definition: Rot2.cpp:89
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Point2 unrotate_(const Rot2 &R, const Point2 &p)
Definition: testRot2.cpp:122
Point3_ rotate(const Rot3_ &x, const Point3_ &p)
int main()
Definition: testRot2.cpp:200
Rot2 relativeBearing_(const Point2 &pt)
Definition: testRot2.cpp:135
RowVector3d w
gtsam::Key l1
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
Definition: Lie.h:130
Rot2 T1(0.1)
Expression< T > compose(const Expression< T > &t1, const Expression< T > &t2)
#define CHECK_CHART_DERIVATIVES(t1, t2)
Definition: testLie.h:85
float * p
Class between(const Class &g) const
Definition: Lie.h:51
TEST(LPInitSolver, InfiniteLoopSingleVar)
static Rot2 fromAngle(double theta)
Named constructor from angle in radians.
Definition: Rot2.h:58
Point2 P(0.2, 0.7)
EIGEN_DEVICE_FUNC const SinReturnType sin() const
internal::FixedSizeMatrix< Y, X >::type numericalDerivative11(boost::function< Y(const X &)> h, const X &x, double delta=1e-5)
New-style numerical derivatives using manifold_traits.
Rot2 inverse() const
Definition: Rot2.h:110
Expression< T > between(const Expression< T > &t1, const Expression< T > &t2)
2D rotation
#define GTSAM_CONCEPT_TESTABLE_INST(T)
Definition: Testable.h:174
TangentVector localCoordinates(const Class &g) const
localCoordinates as required by manifold concept: finds tangent vector between *this and g ...
Definition: Lie.h:135


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:49:22