View Javadoc

1   /*
2    * AbstractPolyhedron.java
3    *
4    * Created on November 29, 2007, 9:45 AM
5    *
6    * To change this template, choose Tools | Template Manager
7    * and open the template in the editor.
8    */
9   
10  package org.lcsim.detector.solids;
11  
12  import hep.physics.vec.Hep3Vector;
13  import java.util.ArrayList;
14  import java.util.List;
15  
16  /**
17   *
18   * This solid represents a bounded convex 3D polyhedron.
19   *
20   * @author tknelson
21   */
22  public abstract class AbstractPolyhedron extends AbstractSolid implements IPolyhedron
23  {
24      
25      /** Creates a new instance of AbstractPolyhedron */
26      public AbstractPolyhedron(String name)
27      {
28          super(name);
29      }
30      
31      public Inside inside(Hep3Vector p)
32      {
33          Point3D point = new Point3D(p);
34          
35          boolean inside = true;
36          for (Polygon3D face : getFaces())
37          {
38              if (GeomOp3D.intersects(point,face)) return Inside.SURFACE;
39              inside = inside && (GeomOp3D.distanceBetween(point,face.getPlane()) < 0);
40          }
41          
42          if (inside) return Inside.INSIDE;
43          else return Inside.OUTSIDE;
44      }
45      
46      public List<Polygon3D> getFacesNormalTo(Hep3Vector normal)
47      {
48          List<Polygon3D> faces = new ArrayList<Polygon3D>();
49        
50          for (Polygon3D face : getFaces())
51          {
52              if (GeomOp3D.isNormal(normal,face)) 
53              {
54                  faces.add(face);
55              }
56          }
57          return faces;
58      }
59      
60  }