View Javadoc

1   package org.lcsim.detector.solids;
2   
3   import java.util.ArrayList;
4   import java.util.Arrays;
5   import java.util.List;
6   
7   /**
8    * A Trapezoid solid that is based on Geant4's
9    * <a href="http://www.lcsim.org/software/geant4/doxygen/html/classG4Trd.html">G4Trd class</a>.
10   *
11   * @author Jeremy McCormick
12   * @author Tim Nelson 
13   * @version $Id: Trd.java,v 1.8 2010/04/14 18:24:54 jeremy Exp $
14   */
15  public class Trd extends AbstractPolyhedron
16  {
17      
18      private final static int[] _HEPREP_VERTEX_ORDERING = {2,3,1,0,6,7,5,4};
19      
20      double dx1,dx2,dy1,dy2,dz;
21      double volume;
22      private static final double tolerance=1E-9;
23      
24      public Trd(
25              String name,
26              double dx1,
27              double dx2,
28              double dy1,
29              double dy2,
30              double dz)
31      {
32          super(name);
33          
34          this.dx1=dx1;
35          this.dx2=dx2;
36          this.dy1=dy1;
37          this.dy2=dy2;
38          this.dz=dz;
39      }
40      
41      public double getCubicVolume()
42      {
43          if(volume != 0.)
44          {;}
45          else
46          {
47              volume = 2*dz*( (dx1+dx2)*(dy1+dy2) + (dx2-dx1)*(dy2-dy1)/3 );
48          }
49          return volume;
50      }
51      
52      public double getXHalfLength1()
53      {
54          return dx1;
55      }
56      
57      public double getXHalfLength2()
58      {
59          return dx2;
60      }
61      
62      public double getYHalfLength1()
63      {
64          return dy1;
65      }
66      
67      public double getYHalfLength2()
68      {
69          return dy2;
70      }
71      
72      public double getZHalfLength()
73      {
74          return dz;
75      }
76      
77      // Implementation of IPolyhedron
78      public int[] getHepRepVertexOrdering()
79      {
80          return _HEPREP_VERTEX_ORDERING;
81      }
82      
83      public List<Polygon3D> getFaces()
84      {
85          List<Polygon3D> faces = new ArrayList<Polygon3D>();
86          
87          List<Point3D> vertices = getVertices();
88          
89          // End with normal -Z
90          faces.add(new Polygon3D(Arrays.asList(vertices.get(0),vertices.get(1),vertices.get(3),vertices.get(2))));
91          
92          // End with normal +Z
93          faces.add(new Polygon3D(Arrays.asList(vertices.get(4),vertices.get(5),vertices.get(7),vertices.get(6))));
94          
95          // Bottom side with normal approx. -Y
96          faces.add(new Polygon3D(Arrays.asList(vertices.get(0),vertices.get(4),vertices.get(5),vertices.get(1))));
97          
98          // Top side with normal approx. +Y
99          faces.add(new Polygon3D(Arrays.asList(vertices.get(2),vertices.get(3),vertices.get(7),vertices.get(6))));
100         
101         // Front side with normal approx. -X
102         faces.add(new Polygon3D(Arrays.asList(vertices.get(0),vertices.get(2),vertices.get(6),vertices.get(4))));
103         
104         // Back side iwth normal approx. +X
105         faces.add(new Polygon3D(Arrays.asList(vertices.get(1),vertices.get(5),vertices.get(7),vertices.get(3))));
106         
107         for (Polygon3D face : faces) face.faceOutward();
108         
109         return faces;
110         
111     }
112     
113     public List<LineSegment3D> getEdges()
114     {
115         List<LineSegment3D> edges = new ArrayList<LineSegment3D>();
116         
117         List<Point3D> vertices = getVertices();
118         
119         // From -z to +z
120         edges.add(new LineSegment3D(vertices.get(0),vertices.get(4)));
121         edges.add(new LineSegment3D(vertices.get(1),vertices.get(5)));
122         edges.add(new LineSegment3D(vertices.get(2),vertices.get(6)));
123         edges.add(new LineSegment3D(vertices.get(3),vertices.get(7)));
124         
125         // From -y to +y
126         edges.add(new LineSegment3D(vertices.get(0),vertices.get(1)));
127         edges.add(new LineSegment3D(vertices.get(2),vertices.get(3)));
128         edges.add(new LineSegment3D(vertices.get(4),vertices.get(5)));
129         edges.add(new LineSegment3D(vertices.get(6),vertices.get(7)));
130         
131         // From -x to +x
132         edges.add(new LineSegment3D(vertices.get(0),vertices.get(2)));
133         edges.add(new LineSegment3D(vertices.get(1),vertices.get(3)));
134         edges.add(new LineSegment3D(vertices.get(4),vertices.get(6)));
135         edges.add(new LineSegment3D(vertices.get(5),vertices.get(7)));
136         
137         return edges;
138     }
139     
140     public List<Point3D> getVertices()
141     {
142         List<Point3D> points = new ArrayList<Point3D>();
143         
144         points.add(new Point3D(-dx1,-dy1,-dz));
145         points.add(new Point3D(+dx1,-dy1,-dz));
146         points.add(new Point3D(-dx1,+dy1,-dz));
147         points.add(new Point3D(+dx1,+dy1,-dz));
148         
149         points.add(new Point3D(-dx2,-dy2,+dz));
150         points.add(new Point3D(+dx2,-dy2,+dz));
151         points.add(new Point3D(-dx2,+dy2,+dz));
152         points.add(new Point3D(+dx2,+dy2,+dz));
153         
154         return points;
155     }
156    
157     public String toString()
158     {
159         return this.getClass().getSimpleName()+" "+name+" : x1= "+dx1+ " x2= "+dx2+" y1= "+dy1+" y2="+dy2+ " z= "+dz;
160     }
161 }