Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

/home/xchen/xia/src/dg/demoVectorMatrixTransform.cc

#include <Transform.H>

using namespace xchen;

void  testVector()
{
  cout << "\n\n\n___________________Vector class test___________________\n\n";

  dVector3D d1; d1 = 1., 2.,3.  ,4 ;

  dVector3D d2(-1,-2,-3), d3(d2);
    
  cout << "d1 = " << d1 << endl << "d2 = " << d2 << endl << "d3 = " << d3 << endl << endl;
    
  cout << "d1+d2+d3 = " << d1+d2+d3 << endl;
  cout << "d1 * d2 = " << d1 * d2 << endl;
  cout << "d1 ^ d2 = " << (d1 ^ d2) << endl;
   
  cout << "angle(d1,d2) is " << d1.Angle(d2) << endl;
  cout << "d1 is " << d1 << endl;
    
  d1 = d2;
  cout << "d1 = d2 is " << d1 << endl;

  cout << "d1.GetProjection(d2) is " << d1.GetProjection(d2) << endl;

  
  cVector5D c5('a', 'b','c', 'd', 'e');
  cVector4D c4 = (cVector4D) c5.GetProjection();
  cVector3D c3 = (cVector3D) c4.GetProjection();
  dVector3D db3 = c3;
  dVector2D db2 = (dVector2D) db3.GetProjection();

  cout << "c5 = " << c5 << endl;
  cout << "c4 = c5.GetProjection() is " << c4 << endl;
  cout << "c3 = c4.GetProjection() is " << c3 << endl;
  cout << "db3 = c3 is " << db3 << endl;
  cout << "db2 = db3.GetProjection() is " << db2 << endl;
}




void testMatrix()
{
  cout << "\n\n\n___________________Matrix class test___________________\n\n";
  dVecOfVec33 v33;
  dMatrix33 m33(v33);
  for(int r=0; r<3; r++)
    for(int c=0; c<3; c++)
      {
        m33(r,c) = r*c+2;
        v33[c][r] = -(r*c+2);
      }

  cout << "v33 and m33 should be negative to each other\n";
  cout << "v33 is \n" << v33 << endl;
  cout << "m33 = \n" << m33 << endl;    

  cout << "v33.LinearCombine( dVector3D(1,-1,1) ) is \n" << v33.LinearCombine( dVector3D(1,-1,1) ) << endl;
  cout << "m33 * dVector3D(1,0,1) is \n" << m33 * dVector3D(1,0,1) << endl;
}



void  testTransform()
{
  cout << "\n\n\n___________________Transform class test___________________\n\n";
  Transform trans1;
  trans1.RotateTo(dVector3D(1,-1,-2), dVector3D(-2, 1, 3));
  trans1.RotateZ(90.0);
  trans1.Translate(dVector3D(1,1,1));

  HMatrix m1 = trans1.GetMatrix()();
  cout << "transformation matrix of RotateTo(dVector3D(1,-1,-2), dVector(-2, 1, 3)), then rotateZ(90), and then translate(1,1,1) m1 = \n" << m1 << endl;

  Transform trans2;
  trans1.Translate(dVector3D(-1,-1,-1));
  trans1.RotateZ(-90.0);
  trans1.RotateTo(dVector3D(-2, 1, 3), dVector3D(1,-1,-2));
  trans2.Translate(dVector3D(-1,-1,-1));
  trans2.RotateZ(-90.0);
  trans2.RotateTo(dVector3D(-2, 1, 3), dVector3D(1,-1,-2));

  HMatrix m = trans1.GetMatrix();
  HMatrix m2 = trans2.GetMatrix();

  cout << "transformation matrix of translate(-1,-1,-1), then rotateZ(-90), and then RotateTo(dVector(-2, 1, 3), dVector3D(1,-1,-2)) m2 = \n" << m2 << endl;
  cout << "transformation matrix of translate(-1,-1,-1) then rotateZ(-90), and then RotateTo(dVector(-2, 1, 3), dVector3D(1,-1,-2)) on m1 = \n" << m << endl;

  cout << "should print out an unit matrix m1*m2 = \n" << (m1*m2) << endl;
}

int main()
{
  testVector();
  testMatrix();
  testTransform();
  return 0;
}

Generated on Wed Apr 7 21:40:48 2004 by doxygen1.2.18