| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    testRot2.cpp | 
					
						
							|  |  |  |  * @brief   Unit tests for Rot2 class | 
					
						
							|  |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <CppUnitLite/TestHarness.h>
 | 
					
						
							|  |  |  | #include "numericalDerivative.h"
 | 
					
						
							|  |  |  | #include "Rot2.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Rot2 R(0.1); | 
					
						
							|  |  |  | Point2 P(0.2, 0.7); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Rot2, angle) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-12-18 08:09:54 +08:00
										 |  |  | 	DOUBLES_EQUAL(0.1,R.theta(),1e-9); | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Rot2, transpose) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-08 08:40:17 +08:00
										 |  |  | 	CHECK(assert_equal(inverse(R).matrix(),R.transpose())); | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-14 23:45:45 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Rot2, negtranspose) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-15 00:57:48 +08:00
										 |  |  | 	CHECK(assert_equal(-inverse(R).matrix(),R.negtranspose())); | 
					
						
							| 
									
										
										
										
											2009-12-14 23:45:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Rot2, compose) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-15 00:57:48 +08:00
										 |  |  | 	CHECK(assert_equal(Rot2(0.45), Rot2(0.2)*Rot2(0.25))); | 
					
						
							|  |  |  | 	CHECK(assert_equal(Rot2(0.45), Rot2(0.25)*Rot2(0.2))); | 
					
						
							| 
									
										
										
										
											2009-12-14 23:45:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Rot2, invcompose) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-15 00:57:48 +08:00
										 |  |  | 	CHECK(assert_equal(Rot2(0.2), invcompose(Rot2(0.25),Rot2(0.45)))); | 
					
						
							| 
									
										
										
										
											2009-12-14 23:45:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Rot2, equals) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CHECK(R.equals(R)); | 
					
						
							|  |  |  | 	Rot2 zero; | 
					
						
							|  |  |  | 	CHECK(!R.equals(zero)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-08 08:40:17 +08:00
										 |  |  | TEST( Rot2, expmap) | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	Vector v = zero(1); | 
					
						
							| 
									
										
										
										
											2010-01-08 08:40:17 +08:00
										 |  |  | 	CHECK(assert_equal(expmap(R,v), R)); | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-18 08:09:54 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-08 08:40:17 +08:00
										 |  |  | TEST(Rot2, logmap) | 
					
						
							| 
									
										
										
										
											2009-12-18 08:09:54 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-15 00:57:48 +08:00
										 |  |  | 	Rot2 rot0(M_PI_2); | 
					
						
							|  |  |  | 	Rot2 rot(M_PI); | 
					
						
							|  |  |  | 	Vector expected = Vector_(1, M_PI_2); | 
					
						
							|  |  |  | 	Vector actual = logmap(rot0, rot); | 
					
						
							|  |  |  | 	CHECK(assert_equal(expected, actual)); | 
					
						
							| 
									
										
										
										
											2009-12-18 08:09:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-15 00:57:48 +08:00
										 |  |  | // rotate and derivatives
 | 
					
						
							|  |  |  | inline Point2 rotate_(const Rot2 & R, const Point2& p) {return R.rotate(p);} | 
					
						
							|  |  |  | TEST( Rot2, rotate) | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-15 00:57:48 +08:00
										 |  |  | 	Matrix H1, H2; | 
					
						
							|  |  |  | 	Point2 actual = rotate(R, P, H1, H2); | 
					
						
							|  |  |  | 	CHECK(assert_equal(actual,R*P)); | 
					
						
							|  |  |  | 	Matrix numerical1 = numericalDerivative21(rotate_, R, P); | 
					
						
							|  |  |  | 	CHECK(assert_equal(numerical1,H1)); | 
					
						
							|  |  |  | 	Matrix numerical2 = numericalDerivative22(rotate_, R, P); | 
					
						
							|  |  |  | 	CHECK(assert_equal(numerical2,H2)); | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-15 00:57:48 +08:00
										 |  |  | // unrotate and derivatives
 | 
					
						
							|  |  |  | inline Point2 unrotate_(const Rot2 & R, const Point2& p) {return R.unrotate(p);} | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | TEST( Rot2, unrotate) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-15 00:57:48 +08:00
										 |  |  | 	Matrix H1, H2; | 
					
						
							|  |  |  | 	Point2 w = R * P, actual = unrotate(R, w, H1, H2); | 
					
						
							|  |  |  | 	CHECK(assert_equal(actual,P)); | 
					
						
							|  |  |  | 	Matrix numerical1 = numericalDerivative21(unrotate_, R, w); | 
					
						
							|  |  |  | 	CHECK(assert_equal(numerical1,H1)); | 
					
						
							|  |  |  | 	Matrix numerical2 = numericalDerivative22(unrotate_, R, w); | 
					
						
							|  |  |  | 	CHECK(assert_equal(numerical2,H2)); | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-16 09:16:59 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST( Rot2, relativeBearing ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Point2 l1(1, 0), l2(1, 1); | 
					
						
							|  |  |  | 	Matrix expectedH, actualH; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// establish relativeBearing is indeed zero
 | 
					
						
							|  |  |  | 	Rot2 actual1 = relativeBearing(l1, actualH); | 
					
						
							|  |  |  | 	CHECK(assert_equal(Rot2(),actual1)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check numerical derivative
 | 
					
						
							|  |  |  | 	expectedH = numericalDerivative11(relativeBearing, l1, 1e-5); | 
					
						
							|  |  |  | 	CHECK(assert_equal(expectedH,actualH)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// establish relativeBearing is indeed 45 degrees
 | 
					
						
							|  |  |  | 	Rot2 actual2 = relativeBearing(l2, actualH); | 
					
						
							|  |  |  | 	CHECK(assert_equal(Rot2(M_PI_4),actual2)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check numerical derivative
 | 
					
						
							|  |  |  | 	expectedH = numericalDerivative11(relativeBearing, l2, 1e-5); | 
					
						
							|  |  |  | 	CHECK(assert_equal(expectedH,actualH)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-10 05:50:27 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  | 	TestResult tr; | 
					
						
							|  |  |  | 	return TestRegistry::runAllTests(tr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 |