Garfield++ 4.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/// 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() const { return piv; }
33 vec Gdir() 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)) {}
43 straight(const point& fp1, const point& fp2) : piv(fp1), dir() {
44 pvecerror("straight::straight(const point& fp1, const point& fp2)");
45 check_econd12(fp1, ==, fp2, mcerr);
46 dir = unit_vec(fp2 - fp1);
47 }
48 straight(const plane pl1, const plane pl2);
49 // different parallel vecerror=2
50 // the same planes vecerror=3
51 straight(const point* pt, int qpt, int anum); // interpolates by xi2
52 // residuals are calculated in planes normal to axis which is measured.
53 // This axis is given by anum. 0 - x, 1 - y, 2 - z.
54 // Unless I've mistaken, the line should necessary be directed
55 // toward increasing of this axis.
56 straight(const straight sl[4], point pt[2], vfloat prec);
57 // Draws line via four lines by interpolation.
58 // pt[2] are starting points for two intermidiate layers
59 straight(straight* sl, // array of lines via which it need to draw
60 // this line
61 int qsl, // number of lines in array
62 const straight& sl_start, // first approximation
63 int anum, // prolong axis : 0 - x, 1 - y, 2 - z.
64 vfloat precision, // wanted precision
65 vfloat* dist, // array of distances,
66 // they may be negative as in vecdistance
67 // For vecdistance this is this line
68 point (*pt)[2], // points, pt[][0] is point on this line
69 // pt[][1] is point on line sl.
70 vfloat& mean2dist); // mean square distance
71 // The constructor draws straight line via qsl lines by xi-2 method
72 // residuals are calculated in planes normal to axis which is measured.
73 // This axis is given by anum. 0 - x, 1 - y, 2 - z.
74 // The algorithm finds closest points in sl[] to this line and
75 // draws new this line by call of
76 // straight(const point* pt, int qpt, int anum); // interpolates by xi2
77 // This is being done in loop while
78 // while(mean2dist_prev<mean2dist ||
79 // (mean2dist != 0 && mean2dist_prev-mean2dist>precision) );
80
81 /// Copy assignment operator.
83 piv = fsl.piv;
84 dir = fsl.dir;
85 return *this;
86 }
87 /// Copy constructor.
88 straight(const straight& s) : piv(s.piv), dir(s.dir) {}
89
90 // The same line can have different piv's along it, and different vec's:
91 // dir or -dir.
92 friend int operator==(const straight& sl1, const straight& sl2);
93 friend int operator!=(const straight& sl1, const straight& sl2) {
94 return sl1 == sl2 ? 0 : 1;
95 }
96 friend bool apeq(const straight& sl1, const straight& sl2, vfloat prec);
97
98 /// Calculate distance of a point from the line and compare it with prec.
99 /// Return 1 if the point is on the line.
100 int check_point_in(const point& fp, vfloat prec) const;
101
102 /** Figure out whether the line crosses another straight line
103 * (within a precision prec).
104 * - Lines cross in one point (with precision prec) vecerror = 0
105 * - Lines do not cross vecerror = 1
106 * - Lines are parallel vecerror = 2
107 * - Lines are identical vecerror = 3
108 */
109 point cross(const straight& sl, vfloat prec) const;
110
111 /// Shortest distance between two lines, may be negative.
112 vfloat vecdistance(const straight& sl, int& type_of_cross, point pt[2]) const;
113 // type_of_cross has same meaning as vecerror from previous function,
114 // But the precision is assumed to be 0.
115 // pt inited only for type_of_cross == 1 and 0.
116 // For type_of_cross == 0 pt[0]==pt[1]
117 // pt[0] is point on this line. pt[1] it point on line sl.
118 // It draws
119 // ez = unit_vec(this->dir)
120 // ey = unit_vec(this->dir || sl.dir)
121 // ex = ey || ez
122 // and declares syscoor with this->piv.
123 // vecdistance is just y-coordinate of point of crossing of sl converting
124 // to new syscoor with plane (ey, ez).
125
126 vfloat distance(const straight& sl, int& type_of_cross, point pt[2]) const;
127 // shortest distance between lines, always positive.
128 // type_of_cross has same meaning as vecerror from previous function
129 // But the precision is assumed to be 0.
130 // pt is inited only for type_of_cross == 1 and 0.
131 // For type_of_cross == 0 pt[0]==pt[1]
132 // pt[0] is point on this line. pt[1] is point on line sl.
133 // It is absolute value of vecdistance
134
135 vfloat distance(const point& fpt) const;
136 vfloat distance(const point& fpt, point& fcpt) const;
137 // calculates closest point on the line
138
139 point vecdistance(const vec normal, const straight& slt);
140 // space position of cross of plane with normal, may be negative
141 // not debugged
142
143 friend std::ostream& operator<<(std::ostream& file, const straight& s);
144};
145
146std::ostream& operator<<(std::ostream& file, const straight& s);
147}
148
149#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:368
Straight line, as combination of vector and point.
Definition: straight.h:24
point cross(const straight &sl, vfloat prec) const
Definition: straight.cpp:53
point piv
Origin point, pivot.
Definition: straight.h:27
vfloat vecdistance(const straight &sl, int &type_of_cross, point pt[2]) const
Shortest distance between two lines, may be negative.
Definition: straight.cpp:72
point Gpiv() const
Definition: straight.h:32
friend int operator!=(const straight &sl1, const straight &sl2)
Definition: straight.h:93
vec Gdir() const
Definition: straight.h:33
friend std::ostream & operator<<(std::ostream &file, const straight &s)
Definition: straight.cpp:302
friend int operator==(const straight &sl1, const straight &sl2)
Definition: straight.cpp:31
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:136
straight(const point &fp1, const point &fp2)
Definition: straight.h:43
int check_point_in(const point &fp, vfloat prec) const
Definition: straight.cpp:47
virtual absref_transmit get_components() override
Definition: straight.cpp:23
straight & operator=(const straight &fsl)
Copy assignment operator.
Definition: straight.h:82
vec dir
Direction, unit vector.
Definition: straight.h:29
straight(const straight &s)
Copy constructor.
Definition: straight.h:88
static absref absref::* aref[2]
Definition: straight.h:37
Definition: vec.h:179
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