Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
circumf.cpp
Go to the documentation of this file.
3/*
4Copyright (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
15namespace Heed {
16
17absref absref::*(circumf::aref[2]) = {(absref absref::*)&circumf::piv,
18 (absref absref::*)&circumf::dir};
19
20circumf::circumf() : piv(), dir(), rad(0) {}
21circumf::circumf(const point& fpiv, const vec& fdir, vfloat frad)
22 : piv(fpiv), dir(), rad(frad) {
23 pvecerror("circumf(...)");
24 check_econd11(fdir.length(), == 0, mcerr);
25 dir = unit_vec(fdir);
26}
28 : absref(f), piv(f.piv), dir(f.dir), rad(f.rad) {}
29
31 return absref_transmit(2, aref);
32}
33
34int operator==(const circumf& f1, const circumf& f2) {
35 pvecerror("int operator==(const circumf &f1, const circumf &f2)");
36
37 if (!(f1.dir == f2.dir || f1.dir == -f2.dir)) return 0;
38 if (f1.piv == f2.piv && f1.rad == f2.rad)
39 return 1;
40 else
41 return 0;
42}
43
44bool apeq(const circumf& f1, const circumf& f2, vfloat prec) {
45 pvecerror("bool apeq(const circumf &f1, const circumf &f2, vfloat prec)");
46 if (check_par(f1.dir, f2.dir, prec) == 0) return false;
47 return apeq(f1.piv, f2.piv, prec) && apeq(f1.rad, f2.rad, prec);
48}
49
50int circumf::check_point_in(const point& fp, vfloat prec) const {
51 // returns 1 if point on the circumference
52 pvecerror("int circumf::check_point_in(const point &fp, vfloat prec) const");
53 vec d = fp - piv;
54 if (check_perp(d, dir, prec) != 1) return 0;
55 if (apeq(d.length(), rad)) return 1;
56 return 0;
57}
58int circumf::cross(const plane& pn, point pt[2], vfloat prec) const {
59 pvecerror("int circumf::cross(const plane& pn, point pt[2]) const");
60 if (pn.distance(piv) > rad) return 0; // to avoid cross at very far pn
61 plane pnc(piv, dir);
62 straight sl(pnc, pn);
63 if (vecerror == 3) {
64 vecerror = 0;
65 return -1;
66 }
67 if (vecerror == 2) {
68 vecerror = 0;
69 return 0;
70 }
71 point closest_pt;
72 vfloat d = sl.distance(piv, closest_pt);
73 if (apeq(d, rad, prec)) {
74 pt[0] = closest_pt;
75 return 1;
76 }
77 if (d > rad) return 0;
78 vfloat cat = sqrt(rad * rad - d * d);
79 pt[0] = closest_pt + cat * sl.Gdir();
80 pt[1] = closest_pt - cat * sl.Gdir();
81 return 2;
82}
83
84std::ostream& operator<<(std::ostream& file, const circumf& f) {
85 Ifile << "circumf(erence):\n";
86 indn.n += 2;
87 Ifile << "rad=" << f.rad << '\n';
88 file << f.piv << f.dir;
89 indn.n -= 2;
90 return file;
91}
92}
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:155
Circumference, determined by point (center), normal vector, and radius.
Definition: circumf.h:23
circumf()
Default constructor.
Definition: circumf.cpp:20
int cross(const plane &pn, point pt[2], vfloat prec) const
Definition: circumf.cpp:58
virtual absref_transmit get_components() override
Definition: circumf.cpp:30
friend bool apeq(const circumf &f1, const circumf &f2, vfloat prec)
Definition: circumf.cpp:44
vfloat rad
Radius, >0.
Definition: circumf.h:64
static absrefabsref::*[2] aref
Definition: circumf.h:67
int check_point_in(const point &fp, vfloat prec) const
Return 1 if point on the circumference.
Definition: circumf.cpp:50
point piv
Central point, pivot.
Definition: circumf.h:59
Plane, defined by defined by a point and a vector normal to the plane.
Definition: plane.h:24
vfloat distance(const point &fpt) const
Definition: plane.cpp:149
Point.
Definition: vec.h:366
Definition of straight line, as combination of vector and point.
Definition: straight.h:24
vec Gdir(void) const
Definition: straight.h:33
vfloat distance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:137
Definition: vec.h:177
vfloat length() const
Definition: vec.h:194
Definition: BGMesh.cpp:6
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:37
int vecerror
Definition: vec.cpp:29
bool apeq(const circumf &f1, const circumf &f2, vfloat prec)
Definition: circumf.cpp:44
int operator==(const circumf &f1, const circumf &f2)
Definition: circumf.cpp:34
indentation indn
Definition: prstream.cpp:15
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:314
double vfloat
Definition: vfloat.h:16
#define Ifile
Definition: prstream.h:196
#define mcerr
Definition: prstream.h:128
#define pvecerror(string)
Definition: vec.h:28