// Test the eigenvalue finder. Set up a diagonal matrix and conjugate // by a rotation. That way we obtain a symmetric matrix that can be // diagonalized. Check if the eigenvalue finder reveals the original // diagonal elements. void testEigenvalues() { matrix3x3 Diagonal; for(int i=0; i<3; i++) for(int j=0; j<3; j++) Diagonal.Set(i, j, 0.0); Diagonal.Set(0, 0, randomizer.NextFloat()); Diagonal.Set(1, 1, Diagonal.Get(0,0)+fabs(randomizer.NextFloat())); Diagonal.Set(2, 2, Diagonal.Get(1,1)+fabs(randomizer.NextFloat())); // test the isDiagonal() method VERIFY( Diagonal.isDiagonal() ); matrix3x3 rndRotation; rndRotation.randomRotation(randomizer); // check that rndRotation is really a rotation, i.e. that randomRotation() works VERIFY( rndRotation.isOrthogonal() ); matrix3x3 toDiagonalize = rndRotation * Diagonal * rndRotation.inverse(); VERIFY( toDiagonalize.isSymmetric() ); vector3 eigenvals; toDiagonalize.findEigenvectorsIfSymmetric(eigenvals); for(unsigned int j=0; j<3; j++) VERIFY( IsNegligible( eigenvals[j] - Diagonal.Get(j,j), Diagonal.Get(2,2) ) ); VERIFY( eigenvals[0] < eigenvals[1] && eigenvals[1] < eigenvals[2] ); }
/*! The axis of the rotation will be uniformly distributed on the unit sphere and the angle will be uniformly distributed in the interval 0..360 degrees. */ void matrix3x3::randomRotation(OBRandom &rnd) { double rotAngle; vector3 v1; v1.randomUnitVector(&rnd); rotAngle = 360.0 * rnd.NextFloat(); this->RotAboutAxisByAngle(v1,rotAngle); }
void pickRandom( double & d ) { d = randomizer.NextFloat() * 2.0 - 1.0; }