Changeset a693d6 for src/Fragmentation/Exporters
- Timestamp:
- Sep 10, 2016, 4:14:02 PM (9 years ago)
- Branches:
- SaturateAtoms_singleDegree
- Children:
- 408415
- Parents:
- fbcbf5
- git-author:
- Frederik Heber <heber@…> (06/05/14 17:17:10)
- git-committer:
- Frederik Heber <heber@…> (09/10/16 16:14:02)
- Location:
- src/Fragmentation/Exporters/unittests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp
rfbcbf5 ra693d6 46 46 47 47 #include <boost/assign.hpp> 48 #include <boost/math/quaternion.hpp> 48 49 49 50 #include "CodePatterns/Assert.hpp" 50 51 #include "CodePatterns/Log.hpp" 52 53 #include "LinearAlgebra/Line.hpp" 51 54 52 55 #include "Fragmentation/Exporters/SphericalPointDistribution.hpp" … … 77 80 } 78 81 82 void SphericalPointDistributionTest::QuaternionTest() 83 { 84 Vector oldCenter(0.,1.,0.); 85 Vector newCenter(1.,0.,0.); 86 87 { 88 // setup quaternion 89 Vector RotationAxis = newCenter; 90 RotationAxis.VectorProduct(oldCenter); 91 RotationAxis.Normalize(); 92 const double RotationAngle = oldCenter.Angle(newCenter)/(M_PI/2.); 93 // RotationAxis.Angle(oldCenter) - RotationAxis.Angle(newCenter); 94 boost::math::quaternion<double> q 95 (RotationAngle, RotationAxis[0], RotationAxis[1], RotationAxis[2]); 96 LOG(5, "DEBUG: RotationAxis is " << RotationAxis 97 << ", RotationAngle is " << RotationAngle); 98 LOG(5, "DEBUG: Quaternion describing rotation is " << q); 99 boost::math::quaternion<double> q_inverse = 100 boost::math::conj(q)/(boost::math::norm(q)); 101 LOG(5, "DEBUG: Quaternion inverse is " << q_inverse); 102 boost::math::quaternion<double> identity(1,0,0,0); 103 const boost::math::quaternion<double> unity = q*q_inverse; 104 LOG(5, "DEBUG: q * q^-1 is " << unity); 105 CPPUNIT_ASSERT( boost::math::norm(unity - identity) < std::numeric_limits<double>::epsilon()*1e4); 106 107 // check that rotation works 108 boost::math::quaternion<double> p(0., newCenter[0], newCenter[1], newCenter[2]); 109 LOG(5, "DEBUG: Original newCenter is " << p); 110 p = p * q_inverse; 111 p = q * p; 112 LOG(5, "DEBUG: Rotated newCenter is " << p); 113 boost::math::quaternion<double> comparison(0., -oldCenter[0], oldCenter[1], oldCenter[2]); 114 LOG(5, "DEBUG: Difference norm is " << boost::math::norm(p - comparison)); 115 CPPUNIT_ASSERT( boost::math::norm(p - comparison) < std::numeric_limits<double>::epsilon()*1e4); 116 } 117 118 // rotating with angle = 0 flips the vector unwantedly 119 { 120 // setup quaternion 121 Vector RotationAxis = newCenter; 122 RotationAxis.VectorProduct(oldCenter); 123 RotationAxis.Normalize(); 124 const double RotationAngle = 0.; 125 // RotationAxis.Angle(oldCenter) - RotationAxis.Angle(newCenter); 126 boost::math::quaternion<double> q 127 (RotationAngle, RotationAxis[0], RotationAxis[1], RotationAxis[2]); 128 LOG(5, "DEBUG: RotationAxis is " << RotationAxis 129 << ", RotationAngle is " << RotationAngle); 130 LOG(5, "DEBUG: Quaternion describing rotation is " << q); 131 boost::math::quaternion<double> q_inverse = 132 boost::math::conj(q)/(boost::math::norm(q)); 133 LOG(5, "DEBUG: Quaternion inverse is " << q_inverse); 134 boost::math::quaternion<double> identity(1,0,0,0); 135 const boost::math::quaternion<double> unity = q*q_inverse; 136 LOG(5, "DEBUG: q * q^-1 is " << unity); 137 CPPUNIT_ASSERT( boost::math::norm(unity - identity) < std::numeric_limits<double>::epsilon()*1e4); 138 139 // check that rotation works 140 boost::math::quaternion<double> p(0., newCenter[0], newCenter[1], newCenter[2]); 141 boost::math::quaternion<double> comparison(0., -newCenter[0], newCenter[1], newCenter[2]); 142 LOG(5, "DEBUG: Original newCenter is " << p); 143 p = p * q_inverse; 144 p = q * p; 145 LOG(5, "DEBUG: Rotated newCenter is " << p); 146 LOG(5, "DEBUG: Difference norm is " << boost::math::norm(p - comparison)); 147 CPPUNIT_ASSERT( boost::math::norm(p - comparison) < std::numeric_limits<double>::epsilon()*1e4); 148 } 149 } 150 79 151 /** UnitTest for matchSphericalPointDistributions() with two points 80 152 */ … … 126 198 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 127 199 } 200 201 // test with one point, full rotation 202 { 203 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248)); 204 SphericalPointDistribution::Polygon_t polygon; 205 polygon += RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI); 206 SphericalPointDistribution::Polygon_t newpolygon = 207 SPD.get<2>(); 208 SphericalPointDistribution::Polygon_t expected; 209 expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI); 210 SphericalPointDistribution::Polygon_t remaining = 211 SphericalPointDistribution::matchSphericalPointDistributions( 212 polygon, 213 newpolygon); 214 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 215 } 128 216 } 129 217 … … 149 237 } 150 238 151 // test with one point, just a flip of axis239 // test with one point, just a flip of x and y axis 152 240 { 153 241 SphericalPointDistribution::Polygon_t polygon; … … 157 245 SphericalPointDistribution::Polygon_t expected = newpolygon; 158 246 expected.pop_front(); // remove first point 247 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin(); 248 iter != expected.end(); ++iter) { 249 std::swap((*iter)[0], (*iter)[1]); 250 (*iter)[0] *= -1.; 251 } 159 252 SphericalPointDistribution::Polygon_t remaining = 160 253 SphericalPointDistribution::matchSphericalPointDistributions( … … 194 287 SphericalPointDistribution::Polygon_t expected = newpolygon; 195 288 expected.pop_front(); // remove first point 289 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin(); 290 iter != expected.end(); ++iter) { 291 std::swap((*iter)[0], (*iter)[1]); 292 (*iter)[0] *= -1.; 293 } 196 294 SphericalPointDistribution::Polygon_t remaining = 197 295 SphericalPointDistribution::matchSphericalPointDistributions( … … 231 329 SphericalPointDistribution::Polygon_t expected = newpolygon; 232 330 expected.pop_front(); // remove first point 331 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin(); 332 iter != expected.end(); ++iter) { 333 std::swap((*iter)[0], (*iter)[1]); 334 (*iter)[0] *= -1.; 335 } 233 336 SphericalPointDistribution::Polygon_t remaining = 234 337 SphericalPointDistribution::matchSphericalPointDistributions( … … 268 371 SphericalPointDistribution::Polygon_t expected = newpolygon; 269 372 expected.pop_front(); // remove first point 373 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin(); 374 iter != expected.end(); ++iter) { 375 std::swap((*iter)[0], (*iter)[1]); 376 (*iter)[0] *= -1.; 377 } 270 378 SphericalPointDistribution::Polygon_t remaining = 271 379 SphericalPointDistribution::matchSphericalPointDistributions( … … 305 413 SphericalPointDistribution::Polygon_t expected = newpolygon; 306 414 expected.pop_front(); // remove first point 415 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin(); 416 iter != expected.end(); ++iter) { 417 std::swap((*iter)[0], (*iter)[1]); 418 (*iter)[0] *= -1.; 419 } 307 420 SphericalPointDistribution::Polygon_t remaining = 308 421 SphericalPointDistribution::matchSphericalPointDistributions( … … 342 455 SphericalPointDistribution::Polygon_t expected = newpolygon; 343 456 expected.pop_front(); // remove first point 344 SphericalPointDistribution::Polygon_t remaining = 345 SphericalPointDistribution::matchSphericalPointDistributions( 346 polygon, 347 newpolygon); 348 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 349 } 350 } 457 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin(); 458 iter != expected.end(); ++iter) { 459 std::swap((*iter)[0], (*iter)[1]); 460 (*iter)[0] *= -1.; 461 } 462 SphericalPointDistribution::Polygon_t remaining = 463 SphericalPointDistribution::matchSphericalPointDistributions( 464 polygon, 465 newpolygon); 466 CPPUNIT_ASSERT_EQUAL( expected, remaining ); 467 } 468 } -
src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.hpp
rfbcbf5 ra693d6 22 22 { 23 23 CPPUNIT_TEST_SUITE( SphericalPointDistributionTest) ; 24 CPPUNIT_TEST ( QuaternionTest ); 24 25 CPPUNIT_TEST ( matchSphericalPointDistributionsTest_2 ); 25 26 CPPUNIT_TEST ( matchSphericalPointDistributionsTest_3 ); … … 34 35 void setUp(); 35 36 void tearDown(); 37 void QuaternionTest(); 36 38 void matchSphericalPointDistributionsTest_2(); 37 39 void matchSphericalPointDistributionsTest_3();
Note:
See TracChangeset
for help on using the changeset viewer.