From a7e016e1efc8149a358b8a04f59f7757a61edcdc Mon Sep 17 00:00:00 2001 From: ganovelli Date: Thu, 3 Jan 2008 17:40:17 +0000 Subject: [PATCH] added RandomRotation --- vcg/math/matrix33.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/vcg/math/matrix33.h b/vcg/math/matrix33.h index df3cd7e0..0dead17f 100644 --- a/vcg/math/matrix33.h +++ b/vcg/math/matrix33.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.18 2007/04/19 14:30:26 pietroni +added RotationMatrix method to calculate rotation matrix along an axis + Revision 1.17 2007/04/07 23:06:47 pietroni Added function RotationMatrix @@ -663,6 +666,35 @@ Matrix33 RotationMatrix(const vcg::Point3 &axis, return matr33; } +/// return a random rotation matrix, from the paper: +/// Fast Random Rotation Matrices, James Arvo +/// Graphics Gems III pp. 117-120 +template + Matrix33 RandomRotation(){ + S x1,x2,x3; + Matrix33 R,H,M,vv; + Point3 v; + R.SetIdentity(); + H.SetIdentity(); + x1 = rand()/S(RAND_MAX); + x2 = rand()/S(RAND_MAX); + x3 = rand()/S(RAND_MAX); + + R[0][0] = cos(S(2)*M_PI*x1); + R[0][1] = sin(S(2)*M_PI*x1); + R[1][0] = - R[0][1]; + R[1][1] = R[0][0]; + + v[0] = cos(2.0 * M_PI * x2)*sqrt(x3); + v[1] = sin(2.0 * M_PI * x2)*sqrt(x3); + v[2] = sqrt(1-x3); + + vv.OuterProduct(v,v); + H -= vv*S(2); + M = H*R*S(-1); + return M; +} + /// typedef Matrix33 Matrix33s; typedef Matrix33 Matrix33i;