View Javadoc

1   package org.lcsim.detector;
2   
3   import org.lcsim.detector.IRotation3D;
4   import org.lcsim.detector.RotationPassiveXYZ;
5   
6   import hep.physics.vec.BasicHep3Vector;
7   import hep.physics.vec.Hep3Vector;
8   import hep.physics.vec.VecOp;
9   import junit.framework.TestCase;
10  import junit.framework.TestSuite;
11  
12  public class Rotation3DTest extends TestCase
13  {		
14      public Rotation3DTest(String name)
15      {
16          super(name);
17      }
18      
19      public static junit.framework.Test suite()
20      {
21          return new TestSuite(Rotation3DTest.class);
22      }
23      
24      protected void setUp() throws Exception
25      {}
26         
27      public void testIdentityIsDefault()
28      {
29      	Rotation3D rotation = new Rotation3D();
30      	assertTrue(rotation.getRotationMatrix().trace() == 3.0);
31      }    
32          
33      public void testSimpleRotationX()
34      {
35      	Hep3Vector coordinate = new BasicHep3Vector(0.0,0.0,1.0);
36      	IRotation3D rotation = new RotationPassiveXYZ(Math.PI / 2, 0, 0);
37      	Hep3Vector result = VecOp.mult(rotation.getRotationMatrix(),coordinate);
38      	System.out.println("90 degree X rotation: Y'=Z");
39      	rotation.printOut(System.out);
40      	System.out.printf("original point -> ( %.4f %.4f %.4f ) \n",coordinate.x(),coordinate.y(),coordinate.z());
41      	System.out.printf("rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
42          rotation.invert();
43          result = VecOp.mult(rotation.getRotationMatrix(),result);
44          System.out.printf("inverse rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
45      }
46      
47      public void testSimpleRotationY()
48      {
49      	Hep3Vector coordinate = new BasicHep3Vector(1.0,0.0,0.0);
50      	IRotation3D rotation = new RotationPassiveXYZ(0, Math.PI / 2, 0);
51      	Hep3Vector result = VecOp.mult(rotation.getRotationMatrix(),coordinate);
52      	System.out.println("90 degree Y rotation: Z'=X");
53      	rotation.printOut(System.out);
54      	System.out.printf("original point -> ( %.4f %.4f %.4f ) \n",coordinate.x(),coordinate.y(),coordinate.z());
55      	System.out.printf("rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
56          rotation.invert();
57          result = VecOp.mult(rotation.getRotationMatrix(),result);
58          System.out.printf("inverse rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
59      }
60          
61      public void testSimpleRotationZ()
62      {
63      	Hep3Vector coordinate = new BasicHep3Vector(0.0,1.0,0.0);
64      	IRotation3D rotation = new RotationPassiveXYZ(0, 0, Math.PI / 2);
65      	Hep3Vector result = VecOp.mult(rotation.getRotationMatrix(),coordinate);
66      	System.out.println("90 degree Z rotation: X'=Y");
67      	rotation.printOut(System.out);
68      	System.out.printf("original point -> ( %.4f %.4f %.4f ) \n",coordinate.x(),coordinate.y(),coordinate.z());
69      	System.out.printf("rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
70          rotation.invert();
71          result = VecOp.mult(rotation.getRotationMatrix(),result);
72          System.out.printf("inverse rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
73      }
74      
75      public void testRotationXYZ()
76      {
77      	Hep3Vector coordinate = new BasicHep3Vector(1.0,2.0,3.0);
78      	IRotation3D rotation = new RotationPassiveXYZ(Math.PI/2, Math.PI/2, Math.PI/2);
79      	Hep3Vector result = VecOp.mult(rotation.getRotationMatrix(),coordinate);
80      	System.out.println("Sequential 90 degree rotations in X,Y,Z: X'=Z, Y'=-Y ,Z'=X");
81      	rotation.printOut(System.out);
82      	System.out.printf("original point -> ( %.4f %.4f %.4f ) \n",coordinate.x(),coordinate.y(),coordinate.z());
83      	System.out.printf("rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
84          rotation.invert();
85          result = VecOp.mult(rotation.getRotationMatrix(),result);
86          System.out.printf("inverse rotated 90 deg -> ( %.4f %.4f %.4f ) \n",result.x(),result.y(),result.z());
87      }
88      
89  }