Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
straight.h
Go to the documentation of this file.
1#ifndef STRAIGHT_H
2#define STRAIGHT_H
3/*
4Definition of straight line, as combination of vector and point.
5
6Copyright (c) 2000 Igor B. Smirnov
7
8The file can be used, copied, modified, and distributed
9according to the terms of GNU Lesser General Public License version 2.1
10as published by the Free Software Foundation,
11and provided that the above copyright notice, this permission notice,
12and notices about any modifications of the original text
13appear in all copies and in supporting documentation.
14The file is provided "as is" without express or implied warranty.
15*/
16#include <iostream>
18
19namespace Heed {
20
21class plane;
22
23// **** straight ****
24
25class straight : public absref {
26 protected:
27 point piv; // origin point, pivot
28 vec dir; // direction, unit vector
29 public:
30 point Gpiv(void) const { return piv; }
31 vec Gdir(void) const {
32 return dir;
33 }
34
35 protected:
36 virtual void get_components(ActivePtr<absref_transmit>& aref_tran);
37 static absref(absref::* aref[2]);
38
39 public:
40 straight() : piv(), dir() {}
41 straight(const point& fpiv, const vec& fdir)
42 : piv(fpiv), dir(unit_vec(fdir)) {
43 }
45 piv = fsl.piv;
46 dir = fsl.dir;
47 return *this;
48 }
49 straight(const point& fp1, const point& fp2) : piv(fp1), dir() {
50 pvecerror("straight::straight(const point& fp1, const point& fp2)");
51 check_econd12(fp1, ==, fp2, mcerr);
52 dir = unit_vec(fp2 - fp1);
53 }
54 straight(const plane pl1, const plane pl2);
55 // different parallel vecerror=2
56 // the same planes vecerror=3
57
58 straight(const point* pt, int qpt, int anum); // interpolates by xi2
59 // residuals are calculated in planes normal to axis which is measured.
60 // This axis is given by anum. 0 - x, 1 - y, 2 - z.
61 // Unless I've mistaken, the line should necessary be directed
62 // toward increasing of this axis.
63
64 straight(const straight sl[4], point pt[2], vfloat prec);
65 // Draws line via four lines by interpolation.
66 // pt[2] are starting points for two intermidiate layers
67
68 // The same line can have different piv's along it, and different vec's:
69 // dir or -dir.
70 friend int operator==(const straight& sl1, const straight& sl2);
71 friend int operator!=(const straight& sl1, const straight& sl2) {
72 return sl1 == sl2 ? 0 : 1;
73 }
74 friend int apeq(const straight& sl1, const straight& sl2, vfloat prec);
75 friend int not_apeq(const straight& sl1, const straight& sl2, vfloat prec) {
76 return apeq(sl1, sl2, prec) == 1 ? 0 : 1;
77 }
78 int check_point_in(const point& fp, vfloat prec) const;
79 // returns 1 if point in the straight line. Calculates distance
80 // and compares it with prec
81
82 point cross(const straight& sl, vfloat prec) const;
83 // figure out whether there is cross, and calculate point, if there is.
84 // good cross in one point (with precision prec) vecerror=0
85 // not crossed lines vecerror=1
86 // different parallel(exactly) lines vecerror=2
87 // the same(exactly) line (piv and dir may differ) vecerror=3
88 // prec set up maximal distance at which lines are considered crossed
89
90 vfloat vecdistance(const straight& sl, int& type_of_cross, point pt[2]) const;
91 // shortest distance between lines, may be negative.
92 // type_of_cross has same meaning as vecerror from previous function,
93 // But the precision is assumed to be 0.
94 // pt inited only for type_of_cross == 1 and 0.
95 // For type_of_cross == 0 pt[0]==pt[1]
96 // pt[0] is point on this line. pt[1] it point on line sl.
97 // It draws
98 // ez = unit_vec(this->dir)
99 // ey = unit_vec(this->dir || sl.dir)
100 // ex = ey || ez
101 // and declares syscoor with this->piv.
102 // vecdistance is just y-coordinate of point of crossing of sl converting
103 // to new syscoor with plane (ey, ez).
104
105 vfloat distance(const straight& sl, int& type_of_cross, point pt[2]) const;
106 // shortest distance between lines, always positive.
107 // type_of_cross has same meaning as vecerror from previous function
108 // But the precision is assumed to be 0.
109 // pt is inited only for type_of_cross == 1 and 0.
110 // For type_of_cross == 0 pt[0]==pt[1]
111 // pt[0] is point on this line. pt[1] is point on line sl.
112 // It is absolute value of vecdistance
113
114 vfloat distance(const point& fpt) const;
115 vfloat distance(const point& fpt, point& fcpt) const;
116 // calculates closest point on the line
117
118 point vecdistance(const vec normal, const straight& slt);
119 // space position of cross of plane with normal, may be negative
120 // not debugged
121
122 straight(straight* sl, // array of lines via which it need to draw
123 // this line
124 int qsl, // number of lines in array
125 const straight& sl_start, // first approximation
126 int anum, // prolong axis : 0 - x, 1 - y, 2 - z.
127 vfloat precision, // wanted precision
128 vfloat* dist, // array of distances,
129 // they may be negative as in vecdistance
130 // For vecdistance this is this line
131 point (*pt)[2], // points, pt[][0] is point on this line
132 // pt[][1] is point on line sl.
133 vfloat& mean2dist); // mean square distance
134 // The constructor draws straight line via qsl lines by xi-2 method
135 // residuals are calculated in planes normal to axis which is measured.
136 // This axis is given by anum. 0 - x, 1 - y, 2 - z.
137 // The algorithm finds closest points in sl[] to this line and
138 // draws new this line by call of
139 // straight(const point* pt, int qpt, int anum); // interpolates by xi2
140 // This is being done in loop while
141 // while(mean2dist_prev<mean2dist ||
142 // (mean2dist != 0 && mean2dist_prev-mean2dist>precision) );
143
144 friend std::ostream& operator<<(std::ostream& file, const straight& s);
145};
146
147std::ostream& operator<<(std::ostream& file, const straight& s);
148
149}
150
151#endif
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:380
point cross(const straight &sl, vfloat prec) const
Definition: straight.cpp:56
vfloat vecdistance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:75
friend int operator!=(const straight &sl1, const straight &sl2)
Definition: straight.h:71
friend std::ostream & operator<<(std::ostream &file, const straight &s)
Definition: straight.cpp:306
friend int operator==(const straight &sl1, const straight &sl2)
Definition: straight.cpp:31
vec Gdir(void) const
Definition: straight.h:31
friend int apeq(const straight &sl1, const straight &sl2, vfloat prec)
Definition: straight.cpp:40
straight(const point &fpiv, const vec &fdir)
Definition: straight.h:41
vfloat distance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:137
straight(const point &fp1, const point &fp2)
Definition: straight.h:49
int check_point_in(const point &fp, vfloat prec) const
Definition: straight.cpp:50
static absrefabsref::*[2] aref
Definition: straight.h:37
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: straight.cpp:23
straight & operator=(const straight &fsl)
Definition: straight.h:44
point Gpiv(void) const
Definition: straight.h:30
friend int not_apeq(const straight &sl1, const straight &sl2, vfloat prec)
Definition: straight.h:75
Definition: vec.h:134
Definition: vec.h:477
Definition: vec.h:248
Definition: BGMesh.cpp:3
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:22
#define mcerr
Definition: prstream.h:135
#define pvecerror(string)
Definition: vec.h:52
double vfloat
Definition: vfloat.h:15