1 package org.lcsim.detector.solids;
2
3 import static java.lang.Math.cos;
4 import static java.lang.Math.sin;
5 import static java.lang.Math.tan;
6
7 import java.util.ArrayList;
8 import java.util.Arrays;
9 import java.util.List;
10
11
12
13
14
15
16
17
18
19
20 public class Trap extends AbstractPolyhedron
21 {
22
23 private final static int[] _HEPREP_VERTEX_ORDERING = {2,3,1,0,6,7,5,4};
24
25 double dz;
26 double TthetaCphi;
27 double TthetaSphi;
28 double dy1;
29 double dx1;
30 double dx2;
31 double Talpha1;
32 double dy2;
33 double dx3;
34 double dx4;
35 double Talpha2;
36 double theta;
37 double phi;
38 double alpha1;
39 double alpha2;
40
41 double cubicVolume;
42
43 public Trap(
44 String name,
45 double dz,
46 double theta,
47 double phi,
48 double dy1,
49 double dx1,
50 double dx2,
51 double alp1,
52 double dy2,
53 double dx3,
54 double dx4,
55 double alp2)
56 {
57 super(name);
58
59 if ( dz > 0 && dy1 > 0 && dx1 > 0 && dx2 > 0 && dy2 > 0 && dx3 > 0 && dx4 > 0 )
60 {
61 this.dz=dz;
62 this.TthetaCphi=tan(theta)*cos(phi);
63 this.TthetaSphi=tan(theta)*sin(phi);
64
65 this.dy1=dy1;
66 this.dx1=dx1;
67 this.dx2=dx2;
68 Talpha1=tan(alp1);
69
70 this.dy2=dy2;
71 this.dx3=dx3;
72 this.dx4=dx4;
73 Talpha2=tan(alp2);
74
75 this.theta = theta;
76 this.phi = phi;
77
78 this.alpha1 = alp1;
79 this.alpha2 = alp2;
80 }
81 else
82 {
83 throw new IllegalArgumentException("bad parameters");
84 }
85 }
86
87 public double getZHalfLength()
88 {
89 return dz;
90 }
91
92 public double getYHalfLength1()
93 {
94 return dy1;
95 }
96
97 public double getXHalfLength1()
98 {
99 return dx1;
100 }
101
102 public double getXHalfLength2()
103 {
104 return dx2;
105 }
106
107 public double getTanAlpha1()
108 {
109 return Talpha1;
110 }
111
112 public double getYHalfLength2()
113 {
114 return dy2;
115 }
116
117 public double getXHalfLength3()
118 {
119 return dx3;
120 }
121
122 public double getXHalfLength4()
123 {
124 return dx4;
125 }
126
127 public double getTanAlpha2()
128 {
129 return Talpha2;
130 }
131
132 public double getTheta()
133 {
134 return theta;
135 }
136
137 public double getPhi()
138 {
139 return phi;
140 }
141
142 public double getAlpha1()
143 {
144 return alpha1;
145 }
146
147 public double getAlpha2()
148 {
149 return alpha1;
150 }
151
152 public double getCubicVolume()
153 {
154 if(cubicVolume != 0.)
155 {;}
156 else
157 { cubicVolume = dz*( (dx1+dx2+dx3+dx4)*(dy1+dy2)
158 + (dx4+dx3-dx2-dx1)*(dy2-dy1)/3 ); }
159 return cubicVolume;
160 }
161
162
163
164 public int[] getHepRepVertexOrdering()
165 {
166 return _HEPREP_VERTEX_ORDERING;
167 }
168
169
170 public List<Polygon3D> getFaces()
171 {
172 List<Polygon3D> faces = new ArrayList<Polygon3D>();
173
174 List<Point3D> vertices = getVertices();
175
176
177 faces.add(new Polygon3D(Arrays.asList(vertices.get(0),vertices.get(1),vertices.get(3),vertices.get(2))));
178
179
180 faces.add(new Polygon3D(Arrays.asList(vertices.get(4),vertices.get(5),vertices.get(7),vertices.get(6))));
181
182
183 faces.add(new Polygon3D(Arrays.asList(vertices.get(0),vertices.get(4),vertices.get(5),vertices.get(1))));
184
185
186 faces.add(new Polygon3D(Arrays.asList(vertices.get(2),vertices.get(3),vertices.get(7),vertices.get(6))));
187
188
189 faces.add(new Polygon3D(Arrays.asList(vertices.get(0),vertices.get(2),vertices.get(6),vertices.get(4))));
190
191
192 faces.add(new Polygon3D(Arrays.asList(vertices.get(1),vertices.get(5),vertices.get(7),vertices.get(3))));
193
194 for (Polygon3D face : faces) face.faceOutward();
195
196 return faces;
197
198 }
199
200 public List<LineSegment3D> getEdges()
201 {
202 List<LineSegment3D> edges = new ArrayList<LineSegment3D>();
203
204 List<Point3D> vertices = getVertices();
205
206
207 edges.add(new LineSegment3D(vertices.get(0),vertices.get(4)));
208 edges.add(new LineSegment3D(vertices.get(1),vertices.get(5)));
209 edges.add(new LineSegment3D(vertices.get(2),vertices.get(6)));
210 edges.add(new LineSegment3D(vertices.get(3),vertices.get(7)));
211
212
213 edges.add(new LineSegment3D(vertices.get(0),vertices.get(1)));
214 edges.add(new LineSegment3D(vertices.get(2),vertices.get(3)));
215 edges.add(new LineSegment3D(vertices.get(4),vertices.get(5)));
216 edges.add(new LineSegment3D(vertices.get(6),vertices.get(7)));
217
218
219 edges.add(new LineSegment3D(vertices.get(0),vertices.get(2)));
220 edges.add(new LineSegment3D(vertices.get(1),vertices.get(3)));
221 edges.add(new LineSegment3D(vertices.get(4),vertices.get(6)));
222 edges.add(new LineSegment3D(vertices.get(5),vertices.get(7)));
223
224 return edges;
225 }
226
227 public List<Point3D> getVertices()
228 {
229 List<Point3D> points = new ArrayList<Point3D>();
230 points.add(new Point3D(-dz*TthetaCphi-dy1*Talpha1-dx1,-dz*TthetaSphi-dy1,-dz));
231 points.add(new Point3D(-dz*TthetaCphi-dy1*Talpha1+dx1,-dz*TthetaSphi-dy1,-dz));
232 points.add(new Point3D(-dz*TthetaCphi+dy1*Talpha1-dx2,-dz*TthetaSphi+dy1,-dz));
233 points.add(new Point3D(-dz*TthetaCphi+dy1*Talpha1+dx2,-dz*TthetaSphi+dy1,-dz));
234 points.add(new Point3D(+dz*TthetaCphi-dy2*Talpha2-dx3,+dz*TthetaSphi-dy2,+dz));
235 points.add(new Point3D(+dz*TthetaCphi-dy2*Talpha2+dx3,+dz*TthetaSphi-dy2,+dz));
236 points.add(new Point3D(+dz*TthetaCphi+dy2*Talpha2-dx4,+dz*TthetaSphi+dy2,+dz));
237 points.add(new Point3D(+dz*TthetaCphi+dy2*Talpha2+dx4,+dz*TthetaSphi+dy2,+dz));
238 return points;
239 }
240
241 public String toString()
242 {
243 return this.getClass().getSimpleName()+" "+name;
244 }
245 }