Commit f51117fa by Dennis Gläser

### [math] implement vector rotation around axis

parent f084cf46
 ... ... @@ -87,6 +87,60 @@ template ctype toRadians(const ctype degrees) { return degrees*M_PI/180.0; } /*! * \brief \todo TODO doc me. Cite Wiki entry. */ template void rotate(Vector& v, const Direction& axis, const ctype angle) { using std::sin; using std::cos; const auto cosPhi = cos(angle); const auto sinPhi = sin(angle); Vector Rx(cosPhi + axis.x()*axis.x()*(1.0 - cosPhi), axis.x()*axis.y()*(1.0 - cosPhi) - axis.z()*sinPhi, axis.x()*axis.z()*(1.0 - cosPhi) - axis.y()*sinPhi); Vector Ry(axis.y()*axis.x()*(1.0 - cosPhi) + axis.z()*sinPhi, cosPhi + axis.y()*axis.y()*(1.0 - cosPhi), axis.y()*axis.z()*(1.0 - cosPhi) - axis.x()*sinPhi); Vector Rz(axis.z()*axis.x()*(1.0 - cosPhi) - axis.y()*sinPhi, axis.z()*axis.y()*(1.0 - cosPhi) + axis.x()*sinPhi, cosPhi + axis.z()*axis.z()*(1.0 - cosPhi)); v = Vector(Rx*v, Ry*v, Rz*v); } /*! * \brief \todo TODO doc me. Cite Wiki entry. */ template void rotate(std::vector>& vectors, const Direction& axis, const ctype angle) { using std::sin; using std::cos; const auto cosPhi = cos(angle); const auto sinPhi = sin(angle); Vector Rx(cosPhi + axis.x()*axis.x()*(1.0 - cosPhi), axis.x()*axis.y()*(1.0 - cosPhi) - axis.z()*sinPhi, axis.x()*axis.z()*(1.0 - cosPhi) - axis.y()*sinPhi); Vector Ry(axis.y()*axis.x()*(1.0 - cosPhi) + axis.z()*sinPhi, cosPhi + axis.y()*axis.y()*(1.0 - cosPhi), axis.y()*axis.z()*(1.0 - cosPhi) - axis.x()*sinPhi); Vector Rz(axis.z()*axis.x()*(1.0 - cosPhi) - axis.y()*sinPhi, axis.z()*axis.y()*(1.0 - cosPhi) + axis.x()*sinPhi, cosPhi + axis.z()*axis.z()*(1.0 - cosPhi)); for (auto& v : vectors) v = Vector(Rx*v, Ry*v, Rz*v); } } // end namespace Frackit #endif // FRACKIT_MATH_HH
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!