GeomConverter/src/org/lcsim/detector/kernel
diff -N CoordinateTransformation3D.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CoordinateTransformation3D.java 23 Feb 2007 21:44:37 -0000 1.1
@@ -0,0 +1,100 @@
+/*
+ * CoordinateTransformation3D.java
+ */
+
+package org.lcsim.detector.kernel;
+
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.VecOp;
+
+/**
+ *
+ * @author tknelson
+ */
+public class CoordinateTransformation3D
+{
+
+ // Fields
+ Hep3Vector _translation = new BasicHep3Vector(0.0,0.0,0.0);
+ Rotation3D _rotation = new Rotation3D();
+
+ /**
+ * Creates a new instance of CoordinateTransformation3D
+ */
+ public CoordinateTransformation3D()
+ {
+ }
+
+ public CoordinateTransformation3D(Rotation3D rotation)
+ {
+ this._rotation = rotation;
+ }
+
+ public CoordinateTransformation3D(Hep3Vector translation)
+ {
+ this._translation = translation;
+ }
+
+ public CoordinateTransformation3D(Hep3Vector translation, Rotation3D rotation)
+ {
+ _translation = translation;
+ _rotation = rotation;
+ }
+
+ // Access to translation and rotation
+ public Hep3Vector getTranslation()
+ {
+ return _translation;
+ }
+
+ public Rotation3D getRotation()
+ {
+ return _rotation;
+ }
+
+ // Transformations
+ public Hep3Vector transform(Hep3Vector coordinates)
+ {
+ translate(coordinates);
+ rotate(coordinates);
+ return coordinates;
+ }
+
+ public Hep3Vector translate(Hep3Vector coordinates)
+ {
+ return VecOp.add(coordinates,_translation);
+ }
+
+ public Hep3Vector rotate(Hep3Vector coordinates)
+ {
+ //return VecOp.mult(_rotation,coordinates);
+ return VecOp.mult(_rotation.getMatrix(),coordinates);
+ }
+
+ // Invert the transformation
+ public void invert()
+ {
+ _translation = VecOp.mult(-1.0,VecOp.mult(_rotation.getMatrix(),_translation));
+ _rotation.invert(); // Need to assure that transpose is used
+ }
+
+ // FIXME: Talk to Tony about supporting this pattern
+
+// public CoordinateTransformation3D inverse()
+// {
+// CoordinateTransformation3D transform = new CoordinateTransformation3D(
+// VecOp.mult(-1.0,VecOp.mult(_rotation,_translation)),
+// _rotation.inverse()); // FIXME: Need to assure that transpose is used
+// return transform;
+// }
+
+ // Static functions
+ public static CoordinateTransformation3D mult(CoordinateTransformation3D transformation1, CoordinateTransformation3D transformation2)
+ {
+ Rotation3D rotation = new Rotation3D(VecOp.mult(transformation1.getRotation().getMatrix(),transformation2.getRotation().getMatrix()));
+ Hep3Vector translation = VecOp.add(VecOp.mult(transformation1.getRotation().getMatrix(),transformation2.getTranslation()),transformation1.getTranslation());
+ return new CoordinateTransformation3D(translation,rotation);
+ }
+
+}
GeomConverter/src/org/lcsim/detector/kernel
diff -N Rotation3D.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Rotation3D.java 23 Feb 2007 21:44:37 -0000 1.1
@@ -0,0 +1,230 @@
+/*
+ * Hep3Rotation.java
+ */
+
+//package org.lcsim.contrib.subdetector.tracker.silicon;
+
+package org.lcsim.detector.kernel;
+
+import hep.physics.vec.BasicHep3Matrix;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.BasicHep3Matrix;
+import hep.physics.vec.Hep3Matrix;
+import hep.physics.vec.VecOp;
+
+import java.io.PrintStream;
+
+/**
+ *
+ * @author tknelson
+ */
+public class Rotation3D
+{
+ private BasicHep3Matrix matrix = BasicHep3Matrix.identity();
+
+ // Fields
+ //=======
+ /**
+ * Create a new Hep3Rotation containing the identify matrix.
+ */
+ public Rotation3D()
+ {}
+
+ /**
+ * Create a new Hep3Rotation from a 3x3 matrix.
+ * @param matrix
+ */
+ public Rotation3D(BasicHep3Matrix matrix)
+ {
+ setMatrix(matrix);
+ }
+
+ public Rotation3D(Hep3Matrix matrix)
+ {
+ setMatrix((BasicHep3Matrix)matrix);
+ }
+
+ public BasicHep3Matrix getMatrix()
+ {
+ return this.matrix;
+ }
+
+ public void setMatrix(BasicHep3Matrix matrix)
+ {
+ this.matrix = matrix;
+ }
+
+ /**
+ * Transform rotation using Tait-Bryan convention.
+ * @param alpha
+ * @param beta
+ * @param gamma
+ */
+ public void setTaitBryan(double alpha, double beta, double gamma)
+ {
+ matrix = passiveTaitBryan(alpha,beta,gamma);
+ }
+
+ public void setPassiveEuler(double phi, double theta, double psi)
+ {
+ matrix.setPassiveEuler(phi,theta,psi);
+ }
+
+ public static BasicHep3Matrix passiveEuler(double phi, double theta, double psi)
+ {
+ BasicHep3Matrix matrix = new BasicHep3Matrix();
+ matrix.setPassiveEuler(phi,theta,psi);
+ return matrix;
+ }
+
+ // Static Methods
+ //===============
+ public static BasicHep3Matrix passiveTaitBryan(double alpha, double beta, double gamma)
+ {
+ return (BasicHep3Matrix)VecOp.mult(passiveZRotation(gamma),VecOp.mult(passiveYRotation(beta),passiveXRotation(alpha)));
+ }
+
+ public static BasicHep3Matrix passiveXRotation(double angle)
+ {
+ double sin = Math.sin(angle);
+ double cos = Math.cos(angle);
+ //Hep3Rotation rotation = new Hep3Rotation();
+ BasicHep3Matrix rotation = new BasicHep3Matrix();
+ rotation.setElement(0,0,cos);
+ rotation.setElement(0,1,sin);
+ rotation.setElement(1,0,-sin);
+ rotation.setElement(1,1,cos);
+ return rotation;
+ }
+
+ public static BasicHep3Matrix passiveYRotation(double angle)
+ {
+ double sin = Math.sin(angle);
+ double cos = Math.cos(angle);
+ //Hep3Rotation rotation = new Hep3Rotation();
+ BasicHep3Matrix rotation = new BasicHep3Matrix();
+
+ // FIXME: Off by 1 error! Indexed from 0.
+ //rotation.setElement(1,3,-sin);
+ //rotation.setElement(3,1,sin);
+ //rotation.setElement(3,3,cos);
+
+ // FIXME: Is this correct?
+ rotation.setElement(1,1,cos);
+ rotation.setElement(1,2,sin);
+ rotation.setElement(2,1,-sin);
+ rotation.setElement(2,2,cos);
+ return rotation;
+ }
+
+ public static BasicHep3Matrix passiveZRotation(double angle)
+ {
+ double sin = Math.sin(angle);
+ double cos = Math.cos(angle);
+ //Hep3Rotation rotation = new Hep3Rotation();
+ BasicHep3Matrix rotation = new BasicHep3Matrix();
+ rotation.setElement(0,0,cos);
+ rotation.setElement(0,1,sin);
+ rotation.setElement(1,0,-sin);
+ rotation.setElement(1,1,cos);
+ return rotation;
+ }
+
+ public void invert()
+ {
+ matrix.invert();
+ }
+
+ public double xx()
+ {
+ return matrix.e(0,0);
+ }
+
+ public double xy()
+ {
+ return matrix.e(0,1);
+ }
+
+ public double xz()
+ {
+ return matrix.e(0,2);
+ }
+
+ public double yx()
+ {
+ return matrix.e(1,0);
+ }
+
+ public double yy()
+ {
+ return matrix.e(1,1);
+ }
+
+ public double yz()
+ {
+ return matrix.e(1,2);
+ }
+
+ public double zx()
+ {
+ return matrix.e(2,0);
+ }
+
+ public double zy()
+ {
+ return matrix.e(2,1);
+ }
+
+ public double zz()
+ {
+ return matrix.e(2,2);
+ }
+
+ Hep3Vector colX()
+ {
+ return new BasicHep3Vector(matrix.e(0,0),matrix.e(1,0),matrix.e(2,0));
+ }
+
+ Hep3Vector colY()
+ {
+ return new BasicHep3Vector(matrix.e(0,1),matrix.e(1,1),matrix.e(2,1));
+ }
+
+ Hep3Vector colZ()
+ {
+ return new BasicHep3Vector(matrix.e(0,2),matrix.e(1,2),matrix.e(2,2));
+ }
+
+ Hep3Vector rowX()
+ {
+ return new BasicHep3Vector(matrix.e(0,0),matrix.e(0,1),matrix.e(0,2));
+ }
+
+ Hep3Vector rowY()
+ {
+ return new BasicHep3Vector(matrix.e(1,0),matrix.e(1,1),matrix.e(1,2));
+ }
+
+ Hep3Vector rowZ()
+ {
+ return new BasicHep3Vector(matrix.e(2,0),matrix.e(2,1),matrix.e(2,2));
+ }
+
+ public void printOut(PrintStream ps)
+ {
+ ps.print("[");
+ ps.println();
+
+ BasicHep3Matrix m = getMatrix();
+
+ for (int i=0; i<3; i++)
+ {
+ ps.printf("%.4f %.4f %.4f", m.e(i,0), m.e(i,1), m.e(i,2));
+ ps.println();
+ }
+
+ ps.print("]");
+ ps.println('\n');
+ }
+}
\ No newline at end of file