Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Vector.h File Reference

Go to the source code of this file.

Classes

struct  Point3D
 
struct  Vector3D
 
struct  DirnCosn3D
 

Macros

#define VGLOBAL   extern
 
#define global2local   1
 
#define local2global   -1
 

Functions

VGLOBAL Point3D CreatePoint3D (double x, double y, double z)
 
VGLOBAL double GetDistancePoint3D (Point3D *a, Point3D *b)
 
VGLOBAL Vector3D CreateDistanceVector3D (Point3D *a, Point3D *b)
 
VGLOBAL double MagVector3D (Vector3D *)
 
VGLOBAL Vector3D UnitVector3D (Vector3D *a)
 
VGLOBAL int PrintPoint3D (Point3D)
 
VGLOBAL int PrintVector3D (Vector3D A)
 
VGLOBAL int PrintDirnCosn3D (DirnCosn3D A)
 
VGLOBAL void VectorRotate_Rect3D (double Xin, double Yin, double Zin, double RotX, double RotY, double RotZ, int Opt, double *Xout, double *Yout, double *Zout)
 
VGLOBAL void CoordRotate_Rect3D (double Xin, double Yin, double Zin, double RotX, double RotY, double RotZ, int Opt, double *Xout, double *Yout, double *Zout)
 
VGLOBAL double Vector3DDotProduct (Vector3D *, Vector3D *)
 
VGLOBAL Vector3D Vector3DCrossProduct (Vector3D *, Vector3D *)
 
VGLOBAL Point3D TranslatePoint3D (Point3D *A, Point3D *Origin, int Sense)
 
VGLOBAL Point3D RotatePoint3D (Point3D *A, DirnCosn3D *Origin, int Sense)
 
VGLOBAL Vector3D RotateVector3D (Vector3D *A, DirnCosn3D *Origin, int Sense)
 
VGLOBAL Point3D TransformPoint3D (Point3D *initial, Point3D *NewOrigin, DirnCosn3D *NewDirns)
 
VGLOBAL Point3D ReflectPoint3DByMirrorAtOrigin (Point3D *p1, Vector3D *n)
 
VGLOBAL double ** MatrixProduct (int NbRows1, int NbCols1, double **Matrix1, int NbRows2, int NbCols2, double **Matrix2)
 

Macro Definition Documentation

◆ global2local

#define global2local   1

◆ local2global

◆ VGLOBAL

#define VGLOBAL   extern

Definition at line 10 of file Vector.h.

Referenced by MatrixProduct().

Function Documentation

◆ CoordRotate_Rect3D()

VGLOBAL void CoordRotate_Rect3D ( double Xin,
double Yin,
double Zin,
double RotX,
double RotY,
double RotZ,
int Opt,
double * Xout,
double * Yout,
double * Zout )

Definition at line 100 of file Vector.c.

103 {
104 double R11, R12, R13, // Follow Numerical Methods Using Matlab
105 R21, R22, R23, // J.H.Mathews and K.D.Fink
106 R31, R32, R33; // 4th Edition, Prentice-Hall of India Pvt. Ltd.
107 double X_X, Y_X, Z_X, // New Delhi, 2004
108 X_Y, Y_Y, Z_Y; // p.115
109
110 if ((fabs(RotX) < 1.0e-12) // A most happy unrotated situation
111 && (fabs(RotY) < 1.0e-12) && (fabs(RotZ) < 1.0e-12)) {
112 *Xout = Xin;
113 *Yout = Yin;
114 *Zout = Zin;
115 return;
116 }
117
118 // Rotation in X
119 if (fabs(RotX) < 1.0e-12) {
120 X_X = Xin;
121 Y_X = Yin;
122 Z_X = Zin;
123 } else {
124 R11 = 1.0;
125 R12 = 0.0;
126 R13 = 0.0;
127 R21 = 0.0;
128 R22 = cos(Opt * RotX);
129 R23 = sin(Opt * RotX);
130 R31 = 0.0;
131 R32 = -sin(Opt * RotX);
132 R33 = cos(Opt * RotX);
133 X_X = R11 * Xin + R12 * Yin + R13 * Zin; // separate matrix multiplication
134 Y_X = R21 * Xin + R22 * Yin + R23 * Zin; // function avoided intentionally.
135 Z_X = R31 * Xin + R32 * Yin + R33 * Zin;
136 }
137
138 // Rotation in Y
139 if (fabs(RotY) < 1.0e-12) {
140 X_Y = X_X;
141 Y_Y = Y_X;
142 Z_Y = Z_X;
143 } else {
144 R11 = cos(Opt * RotY);
145 R12 = 0.0;
146 R13 = -sin(Opt * RotY);
147 R21 = 0.0;
148 R22 = 1.0;
149 R23 = 0.0;
150 R31 = sin(Opt * RotY);
151 R32 = 0.0;
152 R33 = cos(Opt * RotY);
153 X_Y = R11 * X_X + R12 * Y_X + R13 * Z_X; // separate matrix multiplication
154 Y_Y = R21 * X_X + R22 * Y_X + R23 * Z_X; // function avoided intentionally.
155 Z_Y = R31 * X_X + R32 * Y_X + R33 * Z_X;
156 }
157
158 // Rotation in Z - final rotation
159 if (fabs(RotZ) < 1.0e-12) {
160 *Xout = X_Y;
161 *Yout = Y_Y;
162 *Zout = Z_Y;
163 } else {
164 R11 = cos(Opt * RotZ);
165 R12 = sin(Opt * RotZ);
166 R13 = 0.0;
167 R21 = -sin(Opt * RotZ);
168 R22 = cos(Opt * RotZ);
169 R23 = 0.0;
170 R31 = 0.0;
171 R32 = 0.0;
172 R33 = 1.0;
173 *Xout =
174 R11 * X_Y + R12 * Y_Y + R13 * Z_Y; // separate matrix multiplication
175 *Yout =
176 R21 * X_Y + R22 * Y_Y + R23 * Z_Y; // function avoided intentionally.
177 *Zout = R31 * X_Y + R32 * Y_Y + R33 * Z_Y;
178 }
179}
DoubleAc cos(const DoubleAc &f)
Definition DoubleAc.cpp:432
DoubleAc fabs(const DoubleAc &f)
Definition DoubleAc.h:615
DoubleAc sin(const DoubleAc &f)
Definition DoubleAc.cpp:384

◆ CreateDistanceVector3D()

VGLOBAL Vector3D CreateDistanceVector3D ( Point3D * a,
Point3D * b )

Definition at line 198 of file Vector.c.

198 {
199 Vector3D v;
200
201 v.X = b->X - a->X;
202 v.Y = b->Y - a->Y;
203 v.Z = b->Z - a->Z;
204
205 return (v);
206}
double X
Definition Vector.h:22
double Z
Definition Vector.h:24
double Y
Definition Vector.h:23
double Z
Definition Vector.h:31
double Y
Definition Vector.h:30
double X
Definition Vector.h:29

◆ CreatePoint3D()

VGLOBAL Point3D CreatePoint3D ( double x,
double y,
double z )

Definition at line 182 of file Vector.c.

182 {
183 Point3D p;
184 p.X = x;
185 p.Y = y;
186 p.Z = z;
187
188 return (p);
189}

◆ GetDistancePoint3D()

VGLOBAL double GetDistancePoint3D ( Point3D * a,
Point3D * b )

Definition at line 192 of file Vector.c.

192 {
193 return (sqrt((b->X - a->X) * (b->X - a->X) + (b->Y - a->Y) * (b->Y - a->Y) +
194 (b->Z - a->Z) * (b->Z - a->Z)));
195}
DoubleAc sqrt(const DoubleAc &f)
Definition DoubleAc.cpp:314

Referenced by LineKnChPF(), neBEMDiscretize(), PointKnChPF(), and WireKnChPF().

◆ MagVector3D()

VGLOBAL double MagVector3D ( Vector3D * A)

Definition at line 209 of file Vector.c.

209 {
210 double mag;
211
212 mag = sqrt(A->X * A->X + A->Y * A->Y + A->Z * A->Z);
213
214 return (mag);
215}

Referenced by UnitVector3D().

◆ MatrixProduct()

VGLOBAL double ** MatrixProduct ( int NbRows1,
int NbCols1,
double ** Matrix1,
int NbRows2,
int NbCols2,
double ** Matrix2 )

◆ PrintDirnCosn3D()

VGLOBAL int PrintDirnCosn3D ( DirnCosn3D A)

Definition at line 269 of file Vector.c.

269 {
270 printf("XUnit: ");
272 printf("\n");
273 printf("YUnit: ");
275 printf("\n");
276 printf("ZUnit: ");
278 printf("\n");
279 return (0);
280}
int PrintVector3D(Vector3D A)
Definition Vector.c:263
Vector3D ZUnit
Definition Vector.h:38
Vector3D YUnit
Definition Vector.h:37
Vector3D XUnit
Definition Vector.h:36

Referenced by DiscretizeTriangle().

◆ PrintPoint3D()

VGLOBAL int PrintPoint3D ( Point3D A)

Definition at line 257 of file Vector.c.

257 {
258 printf("%lg %lg %lg", A.X, A.Y, A.Z);
259 return (0);
260}

◆ PrintVector3D()

VGLOBAL int PrintVector3D ( Vector3D A)

Definition at line 263 of file Vector.c.

263 {
264 printf("%lg %lg %lg", A.X, A.Y, A.Z);
265 return (0);
266}

Referenced by PrintDirnCosn3D().

◆ ReflectPoint3DByMirrorAtOrigin()

VGLOBAL Point3D ReflectPoint3DByMirrorAtOrigin ( Point3D * p1,
Vector3D * n )

Definition at line 465 of file Vector.c.

465 {
466 double matrix[3][3];
467 matrix[0][0] = -n->X * n->X + n->Y * n->Y + n->Z * n->Z;
468 matrix[0][1] = -2.0 * n->X * n->Y;
469 matrix[0][2] = -2.0 * n->X * n->Z;
470 matrix[1][0] = -2.0 * n->X * n->Y;
471 matrix[1][1] = n->X * n->X - n->Y * n->Y + n->Z * n->Z;
472 matrix[1][2] = -2.0 * n->Y * n->Z;
473 matrix[2][0] = -2.0 * n->X * n->Z;
474 matrix[2][1] = -2.0 * n->Y * n->Z;
475 matrix[2][2] = n->X * n->X + n->Y * n->Y - n->Z * n->Z;
476
477 Point3D p2; // reflected point
478 p2.X = matrix[0][0] * p1->X + matrix[0][1] * p1->Y + matrix[0][2] * p1->Z;
479 p2.Y = matrix[1][0] * p1->X + matrix[1][1] * p1->Y + matrix[1][2] * p1->Z;
480 p2.Z = matrix[2][0] * p1->X + matrix[2][1] * p1->Y + matrix[2][2] * p1->Z;
481
482 return (p2);
483} // ReflectPoint3DByMirrorAtOrigin ends

Referenced by ReflectOnMirror(), and ReflectPrimitiveOnMirror().

◆ RotatePoint3D()

VGLOBAL Point3D RotatePoint3D ( Point3D * A,
DirnCosn3D * Origin,
int Sense )

Definition at line 339 of file Vector.c.

339 {
340 double TransformationMatrix[3][3] = {
341 {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0}};
342 switch (Sense) {
343 case 1:
344 TransformationMatrix[0][0] = DC->XUnit.X;
345 TransformationMatrix[0][1] = DC->XUnit.Y;
346 TransformationMatrix[0][2] = DC->XUnit.Z;
347 TransformationMatrix[1][0] = DC->YUnit.X;
348 TransformationMatrix[1][1] = DC->YUnit.Y;
349 TransformationMatrix[1][2] = DC->YUnit.Z;
350 TransformationMatrix[2][0] = DC->ZUnit.X;
351 TransformationMatrix[2][1] = DC->ZUnit.Y;
352 TransformationMatrix[2][2] = DC->ZUnit.Z;
353 break;
354
355 case -1:
356 TransformationMatrix[0][0] = DC->XUnit.X;
357 TransformationMatrix[0][1] = DC->YUnit.X;
358 TransformationMatrix[0][2] = DC->ZUnit.X;
359 TransformationMatrix[1][0] = DC->XUnit.Y;
360 TransformationMatrix[1][1] = DC->YUnit.Y;
361 TransformationMatrix[1][2] = DC->ZUnit.Y;
362 TransformationMatrix[2][0] = DC->XUnit.Z;
363 TransformationMatrix[2][1] = DC->YUnit.Z;
364 TransformationMatrix[2][2] = DC->ZUnit.Z;
365 break;
366
367 default:
368 printf("Only forward and inverse senses are allowed ...\n");
369 exit(-1);
370 }
371
372 double InitialVector[3] = {A->X, A->Y, A->Z};
373 double FinalVector[3] = {0., 0., 0.};
374 for (int i = 0; i < 3; ++i) {
375 for (int j = 0; j < 3; ++j) {
376 FinalVector[i] += TransformationMatrix[i][j] * InitialVector[j];
377 }
378 }
379 Point3D RotatedPt;
380 RotatedPt.X = FinalVector[0];
381 RotatedPt.Y = FinalVector[1];
382 RotatedPt.Z = FinalVector[2];
383 return (RotatedPt);
384}

Referenced by DiscretizeRectangle(), DiscretizeTriangle(), ReflectOnMirror(), ReflectPrimitiveOnMirror(), and TransformPoint3D().

◆ RotateVector3D()

VGLOBAL Vector3D RotateVector3D ( Vector3D * A,
DirnCosn3D * Origin,
int Sense )

Definition at line 395 of file Vector.c.

395 {
396 double TransformationMatrix[4][4] = {{0.0, 0.0, 0.0, 0.0},
397 {0.0, 0.0, 0.0, 0.0},
398 {0.0, 0.0, 0.0, 0.0},
399 {0.0, 0.0, 0.0, 1.0}};
400 switch (Sense) {
401 case 1:
402 TransformationMatrix[0][0] = DC->XUnit.X;
403 TransformationMatrix[0][1] = DC->XUnit.Y;
404 TransformationMatrix[0][2] = DC->XUnit.Z;
405 TransformationMatrix[1][0] = DC->YUnit.X;
406 TransformationMatrix[1][1] = DC->YUnit.Y;
407 TransformationMatrix[1][2] = DC->YUnit.Z;
408 TransformationMatrix[2][0] = DC->ZUnit.X;
409 TransformationMatrix[2][1] = DC->ZUnit.Y;
410 TransformationMatrix[2][2] = DC->ZUnit.Z;
411 break;
412
413 case -1:
414 TransformationMatrix[0][0] = DC->XUnit.X;
415 TransformationMatrix[0][1] = DC->YUnit.X;
416 TransformationMatrix[0][2] = DC->ZUnit.X;
417 TransformationMatrix[1][0] = DC->XUnit.Y;
418 TransformationMatrix[1][1] = DC->YUnit.Y;
419 TransformationMatrix[1][2] = DC->ZUnit.Y;
420 TransformationMatrix[2][0] = DC->XUnit.Z;
421 TransformationMatrix[2][1] = DC->YUnit.Z;
422 TransformationMatrix[2][2] = DC->ZUnit.Z;
423 break;
424
425 default:
426 printf("Only forward and inverse senses are allowed ...\n");
427 exit(-1);
428 }
429
430 double InitialVector[3] = {A->X, A->Y, A->Z};
431 double FinalVector[3] = {0., 0., 0.};
432 for (int i = 0; i < 3; ++i) {
433 for (int j = 0; j < 3; ++j) {
434 FinalVector[i] += TransformationMatrix[i][j] * InitialVector[j];
435 }
436 }
437 Vector3D RotatedVector;
438 RotatedVector.X = FinalVector[0];
439 RotatedVector.Y = FinalVector[1];
440 RotatedVector.Z = FinalVector[2];
441 return (RotatedVector);
442}

Referenced by AreaKnChPF(), ContinuityChUp(), ContinuityKnCh(), ElePFAtPoint(), GetFluxGCS(), GetPFGCS(), GetPrimPFGCS(), LineKnChPF(), SatisfyContinuity(), Solve(), WireKnChPF(), and WtFldPFAtPoint().

◆ TransformPoint3D()

VGLOBAL Point3D TransformPoint3D ( Point3D * initial,
Point3D * NewOrigin,
DirnCosn3D * NewDirns )

Definition at line 453 of file Vector.c.

454 {
455 Point3D TmpPoint, final;
456
457 TmpPoint = TranslatePoint3D(initial, NewOrigin, 1);
458 final = RotatePoint3D(&TmpPoint, NewDirns, 1);
459 return (final);
460}
Point3D RotatePoint3D(Point3D *A, DirnCosn3D *DC, int Sense)
Definition Vector.c:339
Point3D TranslatePoint3D(Point3D *A, Point3D *Origin, int Sense)
Definition Vector.c:285

◆ TranslatePoint3D()

VGLOBAL Point3D TranslatePoint3D ( Point3D * A,
Point3D * Origin,
int Sense )

Definition at line 285 of file Vector.c.

285 {
286 double InitialVector[4];
287 double TranslationMatrix[4][4] = {{1.0, 0.0, 0.0, 0.0},
288 {0.0, 1.0, 0.0, 0.0},
289 {0.0, 0.0, 1.0, 0.0},
290 {0.0, 0.0, 0.0, 1.0}};
291 double FinalVector[4];
292 Point3D TranslatedPt;
293
294 InitialVector[0] = A->X;
295 InitialVector[1] = A->Y;
296 InitialVector[2] = A->Z;
297 InitialVector[3] = 1.0;
298
299 switch (Sense) {
300 case 1:
301 TranslationMatrix[0][3] = -Origin->X;
302 TranslationMatrix[1][3] = -Origin->Y;
303 TranslationMatrix[2][3] = -Origin->Z;
304 break;
305
306 case -1:
307 TranslationMatrix[0][3] = Origin->X;
308 TranslationMatrix[1][3] = Origin->Y;
309 TranslationMatrix[2][3] = Origin->Z;
310 break;
311
312 default:
313 printf("Only forward and inverse senses are allowed ...\n");
314 exit(-1);
315 }
316
317 for (int i = 0; i < 4; ++i) {
318 FinalVector[i] = 0.0;
319 for (int j = 0; j < 4; ++j) {
320 FinalVector[i] += TranslationMatrix[i][j] * InitialVector[j];
321 }
322 }
323
324 TranslatedPt.X = FinalVector[0];
325 TranslatedPt.Y = FinalVector[1];
326 TranslatedPt.Z = FinalVector[2];
327 return (TranslatedPt);
328}

Referenced by TransformPoint3D().

◆ UnitVector3D()

VGLOBAL Vector3D UnitVector3D ( Vector3D * a)

Definition at line 227 of file Vector.c.

227 {
228 Vector3D u;
229
230 double mag = MagVector3D(v);
231 if (fabs(mag) <= 1.0e-12) {
232 printf("UnitVector3D: magnitude smaller than 1.0e-12; no normalization.\n");
233 u.X = v->X;
234 u.Y = v->Y;
235 u.Z = v->Z;
236 } else {
237 u.X = v->X / mag;
238 u.Y = v->Y / mag;
239 u.Z = v->Z / mag;
240 }
241
242 return (u);
243}
double MagVector3D(Vector3D *A)
Definition Vector.c:209

Referenced by DiscretizeWire(), LineKnChPF(), and WireKnChPF().

◆ Vector3DCrossProduct()

VGLOBAL Vector3D Vector3DCrossProduct ( Vector3D * A,
Vector3D * B )

Definition at line 246 of file Vector.c.

246 {
247 Vector3D product;
248
249 product.X = A->Y * B->Z - A->Z * B->Y;
250 product.Y = A->Z * B->X - A->X * B->Z;
251 product.Z = A->X * B->Y - A->Y * B->X;
252
253 return (product);
254}

Referenced by AreaKnChPF(), DiscretizeRectangle(), DiscretizeTriangle(), DiscretizeWire(), LineKnChPF(), and WireKnChPF().

◆ Vector3DDotProduct()

VGLOBAL double Vector3DDotProduct ( Vector3D * A,
Vector3D * B )

Definition at line 218 of file Vector.c.

218 {
219 double product;
220
221 product = A->X * B->X + A->Y * B->Y + A->Z * B->Z;
222
223 return (product);
224}

◆ VectorRotate_Rect3D()

VGLOBAL void VectorRotate_Rect3D ( double Xin,
double Yin,
double Zin,
double RotX,
double RotY,
double RotZ,
int Opt,
double * Xout,
double * Yout,
double * Zout )

Definition at line 17 of file Vector.c.

20 {
21 double R11, R12, R13, // Follow Numerical Methods Using Matlab
22 R21, R22, R23, // J.H.Mathews and K.D.Fink
23 R31, R32, R33; // 4th Edition, Prentice-Hall of India Pvt. Ltd.
24 double X_X, Y_X, Z_X, // New Delhi, 2004
25 X_Y, Y_Y, Z_Y; // p.115
26
27 if ((fabs(RotX) < 1.0e-12) // A most happy unrotated situation
28 && (fabs(RotY) < 1.0e-12) && (fabs(RotZ) < 1.0e-12)) {
29 *Xout = Xin;
30 *Yout = Yin;
31 *Zout = Zin;
32 return;
33 }
34
35 // Rotation in X
36 if (fabs(RotX) < 1.0e-12) {
37 X_X = Xin;
38 Y_X = Yin;
39 Z_X = Zin;
40 } else {
41 R11 = 1.0;
42 R12 = 0.0;
43 R13 = 0.0;
44 R21 = 0.0;
45 R22 = cos(Opt * RotX);
46 R23 = -sin(Opt * RotX);
47 R31 = 0.0;
48 R32 = sin(Opt * RotX);
49 R33 = cos(Opt * RotX);
50 X_X = R11 * Xin + R12 * Yin + R13 * Zin; // separate matrix multiplication
51 Y_X = R21 * Xin + R22 * Yin + R23 * Zin; // function avoided intentionally.
52 Z_X = R31 * Xin + R32 * Yin + R33 * Zin;
53 }
54
55 // Rotation in Y
56 if (fabs(RotY) < 1.0e-12) {
57 X_Y = X_X;
58 Y_Y = Y_X;
59 Z_Y = Z_X;
60 } else {
61 R11 = cos(Opt * RotY);
62 R12 = 0.0;
63 R13 = sin(Opt * RotY);
64 R21 = 0.0;
65 R22 = 1.0;
66 R23 = 0.0;
67 R31 = -sin(Opt * RotY);
68 R32 = 0.0;
69 R33 = cos(Opt * RotY);
70 X_Y = R11 * X_X + R12 * Y_X + R13 * Z_X; // separate matrix multiplication
71 Y_Y = R21 * X_X + R22 * Y_X + R23 * Z_X; // function avoided intentionally.
72 Z_Y = R31 * X_X + R32 * Y_X + R33 * Z_X;
73 }
74
75 // Rotation in Z - final rotation
76 if (fabs(RotZ) < 1.0e-12) {
77 *Xout = X_Y;
78 *Yout = Y_Y;
79 *Zout = Z_Y;
80 } else {
81 R11 = cos(Opt * RotZ);
82 R12 = -sin(Opt * RotZ);
83 R13 = 0.0;
84 R21 = sin(Opt * RotZ);
85 R22 = cos(Opt * RotZ);
86 R23 = 0.0;
87 R31 = 0.0;
88 R32 = 0.0;
89 R33 = 1.0;
90 *Xout =
91 R11 * X_Y + R12 * Y_Y + R13 * Z_Y; // separate matrix multiplication
92 *Yout =
93 R21 * X_Y + R22 * Y_Y + R23 * Z_Y; // function avoided intentionally.
94 *Zout = R31 * X_Y + R32 * Y_Y + R33 * Z_Y;
95 }
96}