1
2
3
4
5
6
7
8
9
10 package org.lcsim.detector.solids;
11
12 import hep.physics.vec.BasicHep3Vector;
13 import hep.physics.vec.Hep3Vector;
14 import hep.physics.vec.VecOp;
15 import org.lcsim.detector.ITransform3D;
16
17
18
19
20
21 public class Line3D implements Transformable
22 {
23
24 protected Point3D _startpoint;
25 protected Hep3Vector _direction;
26
27
28
29
30 public Line3D()
31 {
32 _startpoint = new Point3D();
33 _direction = new BasicHep3Vector();
34 }
35
36 public Line3D(Point3D startpoint, Hep3Vector direction)
37 {
38 _startpoint = startpoint;
39 _direction = VecOp.unit(direction);
40 }
41
42 public Point3D getStartPoint()
43 {
44 return _startpoint;
45 }
46
47 public Hep3Vector getDirection()
48 {
49 return _direction;
50 }
51
52 public Point3D getEndPoint(double length)
53 {
54 return new Point3D(VecOp.add(_startpoint,VecOp.mult(length,_direction)));
55 }
56
57 public Inside inside(Hep3Vector point)
58 {
59 Hep3Vector v1 = VecOp.sub(point,getStartPoint());
60
61 double v1mag = v1.magnitude();
62
63 if ( Math.abs(VecOp.dot(v1,_direction)) - v1mag < Tolerance.TOLERANCE ) return Inside.INSIDE;
64
65 else return Inside.OUTSIDE;
66
67 }
68
69 public double distanceTo(Line3D line)
70 {
71 Hep3Vector normal = VecOp.cross(line.getDirection(),this.getDirection());
72 Hep3Vector diff = VecOp.sub(line.getStartPoint(),this.getStartPoint());
73 return VecOp.dot(normal,diff)/normal.magnitude();
74 }
75
76 public double distanceTo(Point3D point)
77 {
78 Hep3Vector diff = VecOp.sub(point,this.getStartPoint());
79 return Math.sqrt( diff.magnitudeSquared() - Math.pow(VecOp.dot(diff,this.getDirection()),2) );
80 }
81
82 public void transform(ITransform3D transform)
83 {
84 _startpoint.transform(transform);
85 transform.rotate(_direction);
86 }
87
88 public Line3D transformed(ITransform3D transform)
89 {
90 return new Line3D(_startpoint.transformed(transform),transform.rotated(_direction));
91 }
92
93 }