View Javadoc

1   package org.lcsim.detector.solids;
2   
3   import hep.physics.vec.Hep3Vector;
4   import hep.physics.vec.VecOp;
5   import java.util.List;
6   import org.lcsim.detector.ITransform3D;
7   
8   /**
9    *
10   * @author tknelson
11   */
12  public class Plane3D implements Transformable
13  {
14      
15      Hep3Vector _normal; // normal to plane
16      double _distance; // distance from origin
17      
18      /**
19       * Creates a new instance of Plane3D
20       */
21      public Plane3D(Hep3Vector normal, double distance)
22      {
23          _normal = normal;
24          _distance = distance;
25      }
26      
27      public Plane3D(Hep3Vector normal, Point3D point)
28      {
29          _normal = normal;
30          _distance = VecOp.dot(point,normal);
31      }
32      
33      public Plane3D(List<Point3D> points)
34      {
35          if (points.size()<3)
36          {
37              throw new RuntimeException("Cannot make a plane from less than three points!");
38          }
39          
40          if (!GeomOp3D.coplanar(points))
41          {
42              throw new RuntimeException("Cannot make a single plane from non-coplanar points!");
43          }
44          
45          Hep3Vector v1 = VecOp.sub(points.get(1),points.get(0));
46          Hep3Vector v2 = VecOp.sub(points.get(2),points.get(1));
47          
48          // normal and distance
49          _normal = VecOp.unit(VecOp.cross(v1,v2));
50          _distance = VecOp.dot(_normal,points.get(0));
51      }
52      
53      public Hep3Vector getNormal()
54      {
55          return _normal;
56      }
57      
58      public double getDistance()
59      {
60          return _distance;
61      }
62      
63      public void faceOutward()
64      {
65          if (_distance < 0) reverseNormal();
66      }
67      
68      public void reverseNormal()
69      {
70          _normal = VecOp.mult(-1,_normal);
71          _distance *= -1;
72      }
73      
74      public void transform(ITransform3D transform)
75      {
76          Point3D closest_point = (Point3D)VecOp.mult(_distance,_normal);
77          _distance = closest_point.transformed(transform).magnitude();
78          transform.rotate(_normal);       
79      }
80      
81      public Plane3D transformed(ITransform3D transform)
82      {
83          Point3D closest_point = (Point3D)VecOp.mult(_distance,_normal);
84          return new Plane3D(transform.rotated(_normal),closest_point.transformed(transform).magnitude());
85      }
86      
87  }