1 package org.lcsim.detector;
2
3 import hep.physics.matrix.SymmetricMatrix;
4 import hep.physics.vec.Hep3Vector;
5
6
7
8
9
10
11
12
13
14 public class Transform3D
15 implements ITransform3D
16 {
17
18
19 ITranslation3D _translation = new Translation3D();
20 IRotation3D _rotation = new Rotation3D();
21
22
23
24
25
26 public Transform3D()
27 {}
28
29 public Transform3D(IRotation3D rotation)
30 {
31 this._rotation = rotation;
32 }
33
34 public Transform3D(ITranslation3D translation)
35 {
36 this._translation = translation;
37 }
38
39 public Transform3D(ITranslation3D translation, IRotation3D rotation)
40 {
41 _translation = translation;
42 _rotation = rotation;
43 }
44
45
46 public ITranslation3D getTranslation()
47 {
48 return _translation;
49 }
50
51 private void setTranslation(ITranslation3D translation)
52 {
53 _translation = translation;
54 }
55
56 public IRotation3D getRotation()
57 {
58 return _rotation;
59 }
60
61 private void setRotation(IRotation3D rotation)
62 {
63 _rotation = rotation;
64 }
65
66
67 public void transform(Hep3Vector coordinates)
68 {
69 rotate(coordinates);
70 translate(coordinates);
71 }
72
73 public void transform(SymmetricMatrix matrix)
74 {
75 rotate(matrix);
76 }
77
78 public void translate(Hep3Vector coordinates)
79 {
80 _translation.translate(coordinates);
81 }
82
83 public void rotate(Hep3Vector coordinates)
84 {
85 _rotation.rotate(coordinates);
86 }
87
88 public void rotate(SymmetricMatrix matrix)
89 {
90 _rotation.rotate(matrix);
91 }
92
93
94 public Hep3Vector transformed(Hep3Vector coordinates)
95 {
96 return translated(rotated(coordinates));
97 }
98
99 public SymmetricMatrix transformed(SymmetricMatrix matrix)
100 {
101 return rotated(matrix);
102 }
103
104 public Hep3Vector translated(Hep3Vector coordinates)
105 {
106 return _translation.translated(coordinates);
107 }
108
109 public Hep3Vector rotated(Hep3Vector coordinates)
110 {
111 return _rotation.rotated(coordinates);
112 }
113
114 public SymmetricMatrix rotated(SymmetricMatrix matrix)
115 {
116 return _rotation.rotated(matrix);
117 }
118
119
120 public void invert()
121 {
122 this.setTranslation(inverse().getTranslation());
123 this.setRotation(inverse().getRotation());
124 }
125
126 public Transform3D inverse()
127 {
128 Transform3D transform = new Transform3D(
129 ( new Translation3D(_rotation.inverse().rotated(_translation)).inverse()),
130 _rotation.inverse()
131 );
132 return transform;
133 }
134
135
136 public void multiplyBy(ITransform3D transformation_first)
137 {
138 this.setTranslation(multiply(this,transformation_first).getTranslation());
139 this.setRotation(multiply(this,transformation_first).getRotation());
140 }
141
142 public static Transform3D multiply(ITransform3D transformation_second, ITransform3D transformation_first)
143 {
144 ITranslation3D translation = new Translation3D(transformation_second.translated( transformation_second.rotated(transformation_first.getTranslation()) ) );
145 IRotation3D rotation = Rotation3D.multiply(transformation_second.getRotation(),transformation_first.getRotation());
146
147 return new Transform3D(translation,rotation);
148 }
149
150 public String toString()
151 {
152 return _translation.toString() + '\n' + _rotation.toString();
153 }
154
155 public static Transform3D copy(ITransform3D ci)
156 {
157 Transform3D c = (Transform3D)ci;
158 try { return (Transform3D)c.clone(); } catch (Throwable x) {}
159 return null;
160 }
161
162 public static Transform3D copy(Transform3D c)
163 {
164 try {
165 return (Transform3D)c.clone();
166 }
167 catch (Exception x)
168 {}
169 return null;
170 }
171 }