View Javadoc

1   package org.lcsim.detector.solids;
2   
3   import hep.physics.vec.BasicHep3Vector;
4   import hep.physics.vec.Hep3Vector;
5   import java.text.DecimalFormat;
6   import java.text.NumberFormat;
7   
8   import static java.lang.Math.abs;
9   
10  /**
11   * This class encapsulates the behavior of a polyhedron
12   * whose primary axis is aligned with the z axis and
13   * whose parallel ends are made of isosceles trapezoids.
14   * The trapezoids have a flat base at the bottom.
15   * Also known as a keystone, this is a specialization
16   * of the Trd class.
17   *
18   *           top
19   *    __________________       ^
20   *    \                /       |
21   *     \              /        |
22   *      \            /      Y  |
23   *       \          /          |
24   *        \________/           +------------->
25   *                                    X
26   *          bottom
27   *
28   *
29   * @author Norman A. Graf
30   *
31   * @version $Id: RightIsoscelesTrapezoid.java,v 1.3 2010/04/27 18:55:34 ngraf Exp $
32   */
33  public class RightIsoscelesTrapezoid extends AbstractSolid
34  {
35      //input
36  
37      private double _zHalf;
38      // derived quantities
39      private IsoscelesTrapezoid _face = null;
40      private Hep3Vector[] _vertices = new Hep3Vector[4];
41      private double _volume;
42  
43      /**
44       *  Fully qualified constructor
45       * @param name  the name of this solid
46       * @param bottomHalf the half-width of the base dimension
47       * @param topHalf the half-width of the top dimension
48       * @param yHalf the half-width in the y dimension
49       * @param zHalf the half width in the z dimension
50       */
51      public RightIsoscelesTrapezoid(String name, double bottomHalf, double topHalf, double yHalf, double zHalf)
52      {
53          super(name);
54  
55          _zHalf = zHalf;
56  
57          // counterclockwise starting at lower left corner
58          _vertices[0] = new BasicHep3Vector(-bottomHalf, -yHalf, 0.);
59          _vertices[1] = new BasicHep3Vector(bottomHalf, -yHalf, 0.);
60          _vertices[2] = new BasicHep3Vector(topHalf, yHalf, 0.);
61          _vertices[3] = new BasicHep3Vector(-topHalf, yHalf, 0.);
62  
63          _face = new IsoscelesTrapezoid(bottomHalf, topHalf, yHalf);
64          _volume = _face.area() * _zHalf * 2.;
65      }
66  
67      public double getCubicVolume()
68      {
69          return _volume;
70      }
71  
72      /**
73       * Determines whether a point lies within or outside of this solid.
74       *
75       * @param pos the point to check
76       * @return an enumeration of INSIDE or OUTSIDE ( SURFACE is reported as INSIDE )
77       */
78      public Inside inside(Hep3Vector pos)
79      {
80          //fail fast
81          double z = pos.z();
82          if (abs(z) > _zHalf)
83              return Inside.OUTSIDE;
84  
85          //need to be inside the face...
86          Inside outer = _face.inside(pos);
87          if (outer.compareTo(Inside.OUTSIDE) == 0)
88              return Inside.OUTSIDE;
89  
90          return Inside.INSIDE;
91      }
92  
93      public double zMin()
94      {
95          return -_zHalf;
96      }
97  
98      public double zMax()
99      {
100         return _zHalf;
101     }
102     
103     /**
104      * Return the IsoscelesTrapezoid which forms the face of this solid
105      * @return the face of this solid
106      */
107     public IsoscelesTrapezoid face()
108     {
109         return _face;
110     }
111 
112     @Override
113     public String toString()
114     {
115         NumberFormat formatter = new DecimalFormat("#0.0000");
116 
117         StringBuffer sb = new StringBuffer("RightIsoscelesTrapezoid\n");
118         sb.append(" thickness " + 2. * _zHalf + " \n");
119         sb.append(_face.toString() + " \n");
120         sb.append(" volume " + getCubicVolume() + " \n");
121         return sb.toString();
122     }
123 
124 }