00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <Rotation.hpp>
00021 #include <cmath>
00022
00023 #include <sstream>
00024
00025 TinyVector<3,real_t> Rotation::
00026 operator()(const TinyVector<3,real_t>& v) const
00027 {
00028 return __matrix*v;
00029 }
00030
00031 TinyVector<3,real_t> Rotation::
00032 inverse(const TinyVector<3,real_t>& v) const
00033 {
00034
00035
00036
00037 TinyVector<3,real_t> Temporary = 0;
00038 for (size_t i=0; i<3; i++)
00039 for (size_t j=0; j<3; j++) {
00040 Temporary[i]+=__matrix(j,i)*v[j];
00041 }
00042 return Temporary;
00043 }
00044
00045 Rotation::
00046 Rotation(const TinyVector<3,real_t>& r)
00047 : Transform(rotation),
00048 __angles(r)
00049 {
00050 const real_t deg2rad=4*std::atan(1.)/180.;
00051
00052 const real_t cosx = std::cos(deg2rad*r[0]);
00053 const real_t cosy = std::cos(deg2rad*r[1]);
00054 const real_t cosz = std::cos(deg2rad*r[2]);
00055 const real_t sinx = std::sin(deg2rad*r[0]);
00056 const real_t siny = std::sin(deg2rad*r[1]);
00057 const real_t sinz = std::sin(deg2rad*r[2]);
00058
00059 __matrix(0,0) = cosy*cosz;
00060 __matrix(0,1) = -sinz*cosx + sinx*siny*cosz;
00061 __matrix(0,2) = sinx*sinz + cosx*siny*cosz;
00062 __matrix(1,0) = cosy*sinz;
00063 __matrix(1,1) = cosx*cosz + sinx*siny*sinz;
00064 __matrix(1,2) = -sinx*cosy + cosx*siny*sinz;
00065 __matrix(2,0) = -siny;
00066 __matrix(2,1) = sinx*cosy;
00067 __matrix(2,2) = cosx*cosy;
00068 }
00069
00070 Rotation::
00071 Rotation(const Rotation& r)
00072 : Transform(r),
00073 __angles(r.__angles),
00074 __matrix(r.__matrix)
00075 {
00076 ;
00077 }
00078
00080 std::string Rotation::
00081 povWrite() const
00082 {
00083 std::stringstream povs;
00084 povs << "rotation <"
00085 << __angles[0]
00086 << ", "
00087 << __angles[1]
00088 << ", "
00089 << __angles[2]
00090 << ">";
00091 povs << std::ends;
00092 return povs.str();
00093 }
00094
00095
00096 ReferenceCounting<Transform> Rotation::
00097 getCopy() const
00098 {
00099 return new Rotation(*this);
00100 }