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