Garfield++ v1r0
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
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(length(fdir), == 0, mcerr);
25 dir = unit_vec(fdir);
26}
28 : absref(f), piv(f.piv), dir(f.dir), rad(f.rad) {
29 ;
30}
31
32void circumf::get_components(ActivePtr<absref_transmit>& aref_tran) {
33 aref_tran.pass(new absref_transmit(2, aref));
34}
35
36int operator==(const circumf& f1, const circumf& f2) {
37 pvecerror("int operator==(const circumf &f1, const circumf &f2)");
38
39 if (!(f1.dir == f2.dir || f1.dir == -f2.dir)) return 0;
40 if (f1.piv == f2.piv && f1.rad == f2.rad)
41 return 1;
42 else
43 return 0;
44}
45int apeq(const circumf& f1, const circumf& f2, vfloat prec) {
46 pvecerror("int apeq(const circumf &f1, const circumf &f2, vfloat prec)");
47 if (check_par(f1.dir, f2.dir, prec) == 0) return 0;
48 if (apeq(f1.piv, f2.piv, prec) && apeq(f1.rad, f2.rad, prec)) return 1;
49 return 0;
50}
51
52int circumf::check_point_in(const point& fp, vfloat prec) const {
53 // returns 1 if point on the circumference
54 pvecerror("int circumf::check_point_in(const point &fp, vfloat prec) const");
55 vec d = fp - piv;
56 if (check_perp(d, dir, prec) != 1) return 0;
57 if (apeq(length(d), rad)) return 1;
58 return 0;
59}
60int circumf::cross(const plane& pn, point pt[2], vfloat prec) const {
61 pvecerror("int circumf::cross(const plane& pn, point pt[2]) const");
62 if (pn.distance(piv) > rad) return 0; // to avoid cross at very far pn
63 plane pnc(piv, dir);
64 straight sl(pnc, pn);
65 if (vecerror == 3) {
66 vecerror = 0;
67 return -1;
68 }
69 if (vecerror == 2) {
70 vecerror = 0;
71 return 0;
72 }
73 point closest_pt;
74 vfloat d = sl.distance(piv, closest_pt);
75 if (apeq(d, rad, prec)) {
76 pt[0] = closest_pt;
77 return 1;
78 }
79 if (d > rad) return 0;
80 vfloat cat = sqrt(rad * rad - d * d);
81 pt[0] = closest_pt + cat * sl.Gdir();
82 pt[1] = closest_pt - cat * sl.Gdir();
83 return 2;
84}
85
86std::ostream& operator<<(std::ostream& file, const circumf& f) {
87 Ifile << "circumf(erence):\n";
88 indn.n += 2;
89 Ifile << "rad=" << f.rad << '\n';
90 file << f.piv << f.dir;
91 indn.n -= 2;
92 return file;
93}
94
95}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
int cross(const plane &pn, point pt[2], vfloat prec) const
Definition: circumf.cpp:60
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: circumf.cpp:32
vfloat rad
Definition: circumf.h:30
static absrefabsref::*[2] aref
Definition: circumf.h:40
int check_point_in(const point &fp, vfloat prec) const
Definition: circumf.cpp:52
friend int apeq(const circumf &f1, const circumf &f2, vfloat prec)
Definition: circumf.cpp:45
point piv
Definition: circumf.h:27
vfloat distance(const point &fpt) const
Definition: plane.cpp:153
vec Gdir(void) const
Definition: straight.h:31
vfloat distance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:137
Definition: vec.h:134
Definition: vec.h:477
Definition: vec.h:248
Definition: BGMesh.cpp:3
int apeq(const circumf &f1, const circumf &f2, vfloat prec)
Definition: circumf.cpp:45
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:22
int operator==(const circumf &f1, const circumf &f2)
Definition: circumf.cpp:36
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135
int vecerror
Definition: vec.cpp:31
#define pvecerror(string)
Definition: vec.h:52
double vfloat
Definition: vfloat.h:15