proj home

Files   Classes   Functions   Hierarchy  

d2homogeneous.cpp

Go to the documentation of this file.
00001 
00002 #include <d2homogeneous.h>
00003 
00004 void d2homogeneous::matrixMultiply( point2<double> & p ) const
00005 {
00006   point2<double> p0(p);
00007   p.x = matrix[0]*p0.x + matrix[1]*p0.y + matrix[2];
00008   p.y = matrix[3]*p0.x + matrix[4]*p0.y + matrix[5];
00009 }
00010 
00011 void d2homogeneous::matrixMultiply
00012 ( 
00013   point2<double> & p2,
00014   point2<double> const & p
00015 ) const
00016 {
00017   p2.x = matrix[0]*p.x + matrix[1]*p.y + matrix[2];
00018   p2.y = matrix[3]*p.x + matrix[4]*p.y + matrix[5];
00019 }
00020 
00021 void d2homogeneous::matrixMultiply
00022 ( 
00023   point3<double> & p2,
00024   point3<double> const & p
00025 ) const 
00026 {
00027   point3<double> r;
00028   for (uint i=0; i<3; ++i)
00029   {
00030     rowk(r,i);
00031     p2[i] = r.dot(p);
00032   }
00033 }
00034 
00035 
00036 d2homogeneous::d2homogeneous()
00037 {
00038   setIdentity();
00039 }
00040 
00041 
00042 d2homogeneous::d2homogeneous(doublec * matrix_)
00043 {
00044   for (uint i=0; i<9; ++i)
00045     matrix[i] = matrix_[i];
00046 }
00047 
00048 void d2homogeneous::setZero()
00049 {
00050   for (uint i=0; i<8; ++i)
00051     matrix[i] = 0.0;
00052   matrix[8] = 1.0;
00053 }
00054 
00055 void d2homogeneous::setTranslate(point2<double> const & p)
00056 {
00057   setIdentity();
00058   matrix[2] = p.x;
00059   matrix[5] = p.y;
00060 }
00061 
00062 void d2homogeneous::setRotate(doublec theta)
00063 {
00064   setZero();
00065 
00066   doublec cos_t = cos(theta);
00067   doublec sin_t = sin(theta);
00068   matrix[0] = cos_t;
00069   matrix[1] = -sin_t;
00070   matrix[3] = sin_t;
00071   matrix[4] = cos_t;
00072 }
00073 
00074 void d2homogeneous::setIdentity()
00075 {
00076   matrix[0] = 1.0;  matrix[1] = 0.0;  matrix[2] = 0.0;
00077   matrix[3] = 0.0;  matrix[4] = 1.0;  matrix[5] = 0.0;
00078   matrix[6] = 0.0;  matrix[7] = 0.0;  matrix[8] = 1.0;
00079 }
00080 
00081 
00082 
00083 
00084 d2homogeneous & d2homogeneous::operator *= (d2homogeneous const & w)
00085 {
00086   uint i;
00087   uint k;
00088   point3<double> r;
00089   point3<double> c;
00090   for (i=0; i<3; ++i)
00091   {
00092     rowk(r,i);
00093     for (k=0; k<3; ++k)
00094     {
00095       w.columnk(c,k);
00096       matrix[i*3+k] = r.dot(c);
00097     }
00098   }
00099 
00100   return *this;
00101 }
00102 
00103 void d2homogeneous::setRotateAboutPoint
00104 (
00105   doublec theta, 
00106   point2<double> const & p
00107 )
00108 {
00109   setTranslate(p);
00110 
00111   d2homogeneous r;
00112   r.setRotate(theta);
00113   d2homogeneous pInv;
00114   pInv.setTranslate(p*-1.0);
00115 
00116   (*this)*r*pInv;
00117 }
00118 
00119 d2homogeneous & operator * 
00120 (
00121   d2homogeneous & a, 
00122   d2homogeneous const & b
00123 )
00124 {
00125   return a *= b;
00126 }
00127 
00128 d2homogeneous::operator string() const
00129 {
00130   string s;
00131 
00132   for (uint i=0; i<2; ++i)
00133   {
00134     stringstream ss; 
00135     ss << matrix[i*3] << " ";
00136     ss << matrix[i*3+1] << " ";
00137     ss << matrix[i*3+2] << " \n";
00138 
00139     s+=ss.str();
00140   }
00141 
00142   {
00143     stringstream ss;
00144     ss << matrix[6] << " " << matrix[7] << " " << matrix[8];
00145     s+=ss.str();
00146   }
00147 
00148   return s;
00149 }
00150 
00151 
00152 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8