1 package org.lcsim.recon.tracking.spacegeom;
2 import java.io.*;
3 import static java.lang.Math.sqrt;
4 import static java.lang.Math.acos;
5
6
7
8
9
10
11
12
13
14
15
16 public class SpacePoint implements Serializable, Cloneable
17 {
18 double _x;
19 double _y;
20 double _z;
21 double _xy;
22 double _xyz;
23 double _phi;
24 double _theta;
25
26
27
28
29
30 public SpacePoint()
31 {
32 _x = _y = _z = 0.0;
33 _xy = _xyz = 0.0;
34 _phi = _theta = 0.0;
35 }
36
37
38
39
40
41
42 public SpacePoint( SpacePoint spt )
43 {
44 _x = spt.x();
45 _y = spt.y();
46 _z = spt.z();
47 _xy = spt.rxy();
48 _xyz = spt.rxyz();
49 _phi = spt.phi();
50 _theta = spt.theta();
51 }
52
53
54
55
56
57 public double x()
58 {
59 return _x;
60 }
61
62
63
64
65
66 public double y()
67 {
68 return _y;
69 }
70
71
72
73
74
75
76 public double z()
77 {
78 return _z;
79 }
80
81
82
83
84
85 public double rxy()
86 {
87 return _xy;
88 }
89
90
91
92
93
94 public double phi()
95 {
96 return _phi;
97 }
98
99
100
101
102
103 public double rxyz()
104 {
105 return _xyz;
106 }
107
108
109
110
111
112 public double theta()
113 {
114 return _theta;
115 }
116
117
118
119
120
121 public double cosPhi()
122 {
123 if ( _xy!= 0. ) return _x/_xy;
124 return Math.cos(_phi);
125 }
126
127
128
129
130
131 public double sinPhi()
132 {
133 if ( _xy != 0. ) return _y/_xy;
134 return Math.sin(_phi);
135 }
136
137
138
139
140
141 public double sinTheta()
142 {
143 if ( _xyz != 0. ) return _xy/_xyz;
144 return Math.sin(_theta);
145 }
146
147
148
149
150
151 public double cosTheta()
152 {
153 if ( _xyz != 0. ) return _z/_xyz;
154 return Math.cos(_theta);
155 }
156
157
158
159
160
161
162 public String toString()
163 {
164 return "SpacePoint: " + "\n" +
165 " x: " + x() + "\n" +
166 " y: " + y() + "\n" +
167 " z: " + z() + "\n" +
168 " rxy: " + rxy() + "\n" +
169 " rxyz: " + rxyz() + "\n" +
170 " phi: " + phi() + "\n" +
171 "theta: " + theta() + "\n" ;
172 }
173
174
175
176
177
178
179
180
181 public boolean equals(SpacePoint spt)
182 {
183 return ( x()==spt.x() ) &&
184 ( y()==spt.y() ) &&
185 ( z()==spt.z() );
186 }
187
188
189
190
191
192
193
194
195 public boolean notEquals(SpacePoint spt)
196 {
197 return ! (equals(spt));
198 }
199
200
201
202
203
204
205
206 public static double distance(SpacePoint spt1, SpacePoint spt2)
207 {
208 double dx = spt2.x() - spt1.x();
209 double dy = spt2.y() - spt1.y();
210 double dz = spt2.z() - spt1.z();
211 return Math.sqrt( dx*dx + dy*dy + dz*dz );
212 }
213
214
215
216
217
218
219
220 public static double openingAngle(SpacePoint p1, SpacePoint p2)
221 {
222
223
224 double dot = p1.x()*p2.x()+p1.y()*p2.y()+p1.z()*p2.z();
225
226 double d1 = sqrt(p1.x()*p1.x()+p1.y()*p1.y()+p1.z()*p1.z());
227 double d2 = sqrt(p2.x()*p2.x()+p2.y()*p2.y()+p2.z()*p2.z());
228
229 return acos(dot/(d1*d2));
230 }
231
232
233
234
235
236
237
238 public Object clone()
239 {
240 Object o = null;
241 try
242 {
243 o = super.clone();
244 }
245 catch (CloneNotSupportedException e)
246 {
247 e.printStackTrace();
248 }
249 return o;
250 }
251
252
253
254
255
256
257
258 @Deprecated public double[] getCartesianArray() {
259 return new double[] {_x, _y, _z};
260 }
261 }
262