View Javadoc

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