diff --git a/include/simulation/kinematic.h b/include/simulation/kinematic.h index df35d9c..b644026 100755 --- a/include/simulation/kinematic.h +++ b/include/simulation/kinematic.h @@ -20,6 +20,10 @@ blitz::TinyVector rotateVector(const blitz::TinyVector& v, double theta, double phi); +blitz::TinyVector rotateVector2(const blitz::TinyVector& v, + double theta, + double phi); + blitz::TinyVector rotateVelocityInCenterOfMassFrame( const blitz::TinyVector& velocity_1, const blitz::TinyVector& velocity_2, diff --git a/src/simulation/kinematic.cpp b/src/simulation/kinematic.cpp index 181c547..e2b9727 100755 --- a/src/simulation/kinematic.cpp +++ b/src/simulation/kinematic.cpp @@ -50,6 +50,36 @@ blitz::TinyVector rotateVector(const blitz::TinyVector& v, } } +blitz::TinyVector rotateVector2(const blitz::TinyVector& v, + double theta, + double phi) { + const double norm_value(norm(v)); + if (norm_value == 0) { + return v; + } + const blitz::TinyVector n = v / norm_value; + if (n(2) != -1) { + double denominator = (1 + n(2)); + const double vx = + ((n(1)*n(1)/denominator + n(2))* std::cos(phi) - n(0)*n(1)/denominator + * std::sin(phi)) * std::sin(theta) + + n(0) * std::cos(theta); + const double vy = + ((n(0)*n(0)/denominator + n(2))* std::sin(phi) - n(0)*n(1)/denominator + * std::cos(phi)) * std::sin(theta) + + n(1) * std::cos(theta); + const double vz = + n(2)*std::cos(theta) - (n(1) * std::sin(phi) + n(0)*std::cos(phi)) + *std::sin(theta); + return blitz::TinyVector(vx, vy, vz) * norm_value; + } else { + const double vx = std::sin(theta) * std::cos(phi); + const double vy = std::sin(theta) * std::sin(phi); + const double vz = std::cos(theta); + return -blitz::TinyVector(vx, vy, vz) * norm_value; + } +} + blitz::TinyVector rotateVelocityInCenterOfMassFrame( const blitz::TinyVector& velocity_1, const blitz::TinyVector& velocity_2, @@ -62,7 +92,7 @@ blitz::TinyVector rotateVelocityInCenterOfMassFrame( const blitz::TinyVector v1_in_center_of_mass_frame = velocity_1 - v_center_of_mass; const blitz::TinyVector v1_rot_in_center_of_mass_frame = - rotateVector(v1_in_center_of_mass_frame, theta, phi); + rotateVector2(v1_in_center_of_mass_frame, theta, phi); return v1_rot_in_center_of_mass_frame + v_center_of_mass; }