View Javadoc

1   package org.lcsim.spacegeom;
2   import hep.physics.vec.BasicHep3Vector;
3   import hep.physics.vec.Hep3Vector;
4   import hep.physics.vec.VecOp;
5   
6   import java.io.*;
7   import static hep.physics.vec.VecOp.sub;
8   import static hep.physics.vec.VecOp.add;
9   import static hep.physics.vec.VecOp.mult;
10  
11  
12  /** A vector at a point in space.
13   * The vector can be constructed
14   * in Cartesian, cylindrical or spherical coordinates and components can be
15   * fetched for any of these systems.  The default constructor creates
16   * a vector of zero length at the origin.  Finite vectors of nonzero length
17   * at any point can be constructed using subclasses.
18   *<p>
19   * The point and vector stored in a space vector cannot be modified except
20   * by assignment from another space vector.
21   *<p>
22   * Transformations (translations, rotations, etc) are not provided.
23   * It is expected these will be carried out by external functions which
24   * return new SpacePointVector objects.
25   *<p>
26   * The three orthogonal coordinate systems are defined in the usual way:
27   *<ul>
28   *<li>   Cartesian: (x, y, z)
29   *<li>   Cylindrical: (rxy, phi, z)
30   *<li>   Spherical: (rxyz, theta, phi) .
31   *</ul>
32   * <br>
33   * The rotation from Cartesian to cylindrical:
34   * <br clear="all" /><table border="0" width="100%"><tr><td>
35   * <table align="center"><tr><td nowrap="nowrap" align="center">
36   * </td><td align="left" class="cl"><font face="symbol">
37   * <br /><br /><br /><br />
38   * <br /><br />
39   * </font> </td><td nowrap="nowrap" align="center">
40   * <table>
41   * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
42   * cos<font face="symbol">j</font
43   * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
44   * sin<font face="symbol">j</font
45   * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
46   * 0 </td></tr></table></td></tr>
47   * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
48   * <font face="symbol">-</font
49   * > sin<font face="symbol">j</font
50   * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
51   * cos<font face="symbol">j</font
52   * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
53   * 0 </td></tr></table></td></tr>
54   * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
55   * 0 </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
56   * 0 </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
57   * 1 </td></tr></table></td></tr></table>
58   * </td><td nowrap="nowrap" align="center">
59   * </td><td align="left" class="cl"><font face="symbol">
60   * <br /><br /><br /><br />
61   * <br /><br />
62   * </font></td><td nowrap="nowrap" align="center">
63   * </td></tr></table>
64   * </td></tr></table>
65   *
66   *
67   * <br>
68   * The rotation from cylindrical to Cartesian:
69   * <br clear="all" /><table border="0" width="100%"><tr><td>
70   * <table align="center"><tr><td nowrap="nowrap" align="center">
71   * </td><td align="left" class="cl"><font face="symbol">
72   * <br /><br /><br /><br />
73   * <br /><br />
74   * </font> </td><td nowrap="nowrap" align="center">
75   * <table>
76   * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
77   * cos<font face="symbol">j</font
78   * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
79   * <font face="symbol">-</font
80   * > sin<font face="symbol">j</font
81   * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
82   * 0 </td></tr></table></td></tr>
83   * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
84   * sin<font face="symbol">j</font
85   * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
86   * cos<font face="symbol">j</font
87   * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
88   * 0 </td></tr></table></td></tr>
89   * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
90   * 0 </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
91   * 0 </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
92   * 1 </td></tr></table></td></tr></table>
93   * </td><td nowrap="nowrap" align="center">
94   * </td><td align="left" class="cl"><font face="symbol">
95   * <br /><br /><br /><br />
96   * <br /><br />
97   * </font></td><td nowrap="nowrap" align="center">
98   * </td></tr></table>
99   * </td></tr></table>
100  *
101  *
102  *
103  * <br>
104  * The rotation from Cartesian to spherical:
105  *
106  * <br clear="all" /><table border="0" width="100%"><tr><td>
107  * <table align="center"><tr><td nowrap="nowrap" align="center">
108  * </td><td align="left" class="cl"><font face="symbol">
109  * <br /><br /><br /><br />
110  * <br /><br />
111  * </font> </td><td nowrap="nowrap" align="center">
112  * <table>
113  * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
114  * sin<font face="symbol">J</font
115  * >cos<font face="symbol">j</font
116  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
117  * sin<font face="symbol">J</font
118  * >sin<font face="symbol">j</font
119  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
120  * cos<font face="symbol">J</font
121  * > </td></tr></table></td></tr>
122  * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
123  * cos<font face="symbol">J</font
124  * >cos<font face="symbol">j</font
125  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
126  * cos<font face="symbol">J</font
127  * >sin<font face="symbol">j</font
128  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
129  * <font face="symbol">-</font
130  * > sin<font face="symbol">J</font
131  * > </td></tr></table></td></tr>
132  * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
133  * <font face="symbol">-</font
134  * > sin<font face="symbol">j</font
135  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
136  * cos<font face="symbol">j</font
137  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
138  * 0 </td></tr></table></td></tr></table>
139  * </td><td nowrap="nowrap" align="center">
140  * </td><td align="left" class="cl"><font face="symbol">
141  * <br /><br /><br /><br />
142  * <br /><br />
143  * </font></td><td nowrap="nowrap" align="center">
144  * </td></tr></table>
145  * </td></tr></table>
146  *
147  *
148  * <br>
149  * The rotation from spherical to Cartesian:
150  *
151  * <br clear="all" /><table border="0" width="100%"><tr><td>
152  * <table align="center"><tr><td nowrap="nowrap" align="center">
153  * </td><td align="left" class="cl"><font face="symbol">
154  * <br /><br /><br /><br />
155  * <br /><br />
156  * </font> </td><td nowrap="nowrap" align="center">
157  * <table>
158  * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
159  * sin<font face="symbol">J</font
160  * >cos<font face="symbol">j</font
161  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
162  * cos<font face="symbol">J</font
163  * >cos<font face="symbol">j</font
164  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
165  * <font face="symbol">-</font
166  * > sin<font face="symbol">j</font
167  * > </td></tr></table></td></tr>
168  * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
169  * sin<font face="symbol">J</font
170  * >sin<font face="symbol">j</font
171  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
172  * cos<font face="symbol">J</font
173  * >sin<font face="symbol">j</font
174  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
175  * cos<font face="symbol">j</font
176  * > </td></tr></table></td></tr>
177  * <tr><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
178  * cos<font face="symbol">J</font
179  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
180  * <font face="symbol">-</font
181  * > sin<font face="symbol">J</font
182  * > </td></tr></table></td><td align="center"><table border="0"><tr><td nowrap="nowrap" align="center">
183  * 0 </td></tr></table></td></tr></table>
184  * </td><td nowrap="nowrap" align="center">
185  * </td><td align="left" class="cl"><font face="symbol">
186  * <br /><br /><br /><br />
187  * <br /><br />
188  * </font></td><td nowrap="nowrap" align="center">
189  * </td></tr></table>
190  * </td></tr></table>
191  *
192  *
193  *@author Norman A. Graf
194  *@version $Id: SpacePointVector.java,v 1.1.1.1 2010/12/01 00:15:57 jeremy Exp $
195  *
196  */
197 
198 public class SpacePointVector implements Serializable, Cloneable
199 {
200     SpacePoint startPoint;
201     SpaceVector direction;
202     
203     public SpacePointVector()
204     {
205         startPoint = new SpacePoint();
206         direction = new SpaceVector();
207     }
208     
209     /**
210      * Copy Constructor
211      */
212     public SpacePointVector(SpacePointVector spv)
213     {
214         startPoint = spv.startPoint;
215         direction = spv.direction;
216     }
217     
218     public SpacePointVector(SpacePoint start, SpaceVector dir)
219     {
220         startPoint = start;
221         direction = dir;
222     }
223     
224     public SpacePointVector(SpacePoint start, SpacePoint end)
225     {
226         startPoint = start;
227         // This is expensive
228         direction = new SpaceVector(sub(end, start));
229     }
230     
231     public Object clone()
232     {
233         SpacePoint newStart = (SpacePoint) startPoint.clone();
234         SpaceVector newDirection = new SpaceVector(direction);
235         return new SpacePointVector(newStart, newDirection);
236     }
237     
238     /**
239      * v_x
240      * @return double
241      */
242     public double v_x()
243     {
244         return direction.x();
245     }
246     
247     /**
248      * v_y
249      * @return double
250      */
251     public double v_y()
252     {
253         return direction.y();
254     }
255     
256     /**
257      * v_z
258      * @return double
259      */
260     public double v_z()
261     {
262         return direction.z();
263     }
264     
265     /**
266      * v_rxy
267      * @return double
268      */
269     public double v_rxy()
270     {
271         return direction.rxy();
272     }
273     
274     /**
275      * v_phi
276      * @return double
277      */
278     public double v_phi()
279     {
280         return direction.phi();
281     }
282     
283     /**
284      * v_rxyz
285      * @return double
286      */
287     public double v_rxyz()
288     {
289         return direction.rxyz();
290     }
291     
292     /**
293      * v_theta
294      * @return double
295      */
296     public double v_theta()
297     {
298         return direction.theta();
299     }
300     
301     /**
302      * magnitude
303      * @return double
304      */
305     public double magnitude()
306     {
307         return direction.magnitude();
308     }
309     
310     public boolean equals(SpacePointVector spv)
311     {
312         return startPoint.equals(spv.startPoint) &&
313                 direction.equals(spv.direction);
314     }
315     /**
316      * @return !
317      * @param spv
318      */
319     public boolean notEquals(SpacePointVector spv)
320     {
321         return ! equals(spv);
322     }
323     
324     public SpacePoint getStartPoint()
325     {
326         return startPoint;
327     }
328     
329     public SpacePoint getEndPoint()
330     {
331         return new SpacePoint(add(startPoint, direction));
332     }
333     
334     public SpaceVector getDirection()
335     {
336         return direction;
337     }
338     
339     /**
340      * The SpacePath can be parametrized by its length.
341      * Determines the point in space at a distance alpha
342      * from the Origin.
343      * @param alpha The length parameters. All real values are valid.
344      * @return A SpacePoint at Origin + alpha* (Endpoint - Origin)
345      */
346     public SpacePoint getPointAtLength(double alpha)
347     {
348         return new SpacePoint(add(startPoint, mult(alpha, direction)));
349     }
350     
351     public String toString()
352     {
353 //        return super.toString()
354         return startPoint.toString()
355         + "SpacePointVector:" + "\n"
356                 + "      V_x: " + v_x() + "\n"
357                 + "      V_y: " + v_y() + "\n"
358                 + "      V_z: " + v_z()  + "\n"
359                 + "    V_rxy: " + v_rxy()  + "\n"
360                 + "   V_rxyz: " + v_rxyz()  + "\n"
361                 + "   V_dphi: " + v_phi() + "\n"
362                 + "  V_theta: " + v_theta() + "\n"
363                 + "Magnitude: " + magnitude() + "\n";
364     }
365 }
366 
367 
368 
369 
370 
371 
372 
373