Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
parabol.h
Go to the documentation of this file.
1#ifndef PARABOL_H
2#define PARABOL_H
3
4/*
5Copyright (c) 2001 I. B. Smirnov
6
7Permission to use, copy, modify, distribute and sell this file
8and its documentation for any purpose is hereby granted without fee,
9provided 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.
12It is provided "as is" without express or implied warranty.
13*/
14
15namespace Heed {
16
17/// Solution of quadratic equation.
18/// The main class is colled with a cut of the last character: Parabol
19/// to assure absence of coincidences with any other libraries and user files.
20/// This was inpired by a significant problem with link. The programs
21/// containig this class often don't want to be linked due to missing of
22/// references to functions from this class, if the file compiled from
23/// parabol.c is just included in library. The class parabol does not
24/// contain anything special, but this often happens. Why - unknown.
25/// The mentioned change of name did not solve this problem.
26/// The only solution is the inclusion of the object file parabol.o in the list
27/// of command supplied to linker.
28/// In general, this is very simple class, see definition.
29
30class Parabol {
31 public:
32 double a() const { return da; }
33 double b() const { return db; }
34 double c() const { return dc; }
35 void put_a(const double fa) {
36 da = fa;
37 s_det = 0;
38 s_dxzero = 0;
39 }
40 void put_b(const double fb) {
41 db = fb;
42 s_det = 0;
43 s_dxzero = 0;
44 }
45 void put_c(const double fc) {
46 dc = fc;
47 s_det = 0;
48 s_dxzero = 0;
49 }
50
51 /// Default constructor.
52 Parabol(void) : da(0.0), db(0.0), dc(0.0), s_det(0), s_dxzero(0) {}
53 Parabol(const Parabol& f);
54 Parabol(double fa, double fb, double fc)
55 : da(fa), db(fb), dc(fc), s_det(0), s_dxzero(0) {}
56 /// Constructor from three points.
57 Parabol(double x[3], double y[3]);
58 Parabol(double x[3], double y[3], int);
59 // creates parabola by 3 points, in one of each ,
60 // in the third one, the derivative of the function is supplied instead of
61 // the function. int is any, to differ from previous constructor
62 /// Constructor from 3 points
63 Parabol(double x1, double x2, double x3, double y1, double y2, double y3);
64
65 /// Evaluate the function.
66 double eval(const double x) const { return da * x * x + db * x + dc; }
67
68 // Returns number of solutions. First is the least.
69 int find_zero(double xzero[2]) const;
70 double find_maxmin();
71
72 double determinant() const {
73 const Parabol& t = (*this);
74 if (s_det == 0) {
75 t.s_det = 1;
76 t.det = db * db - 4 * da * dc;
77 }
78 return det;
79 }
80
81 private:
82 double da, db, dc;
83 mutable int s_det;
84 mutable double det;
85 mutable int s_dxzero;
86 mutable int qdxzero;
87 mutable double dxzero[2];
88};
89
90std::ostream& operator<<(std::ostream& file, const Parabol& f);
91}
92
93#endif
void put_a(const double fa)
Definition: parabol.h:35
void put_b(const double fb)
Definition: parabol.h:40
int find_zero(double xzero[2]) const
Definition: parabol.cpp:229
double c() const
Definition: parabol.h:34
Parabol(double fa, double fb, double fc)
Definition: parabol.h:54
double b() const
Definition: parabol.h:33
double find_maxmin()
Definition: parabol.cpp:274
Parabol(void)
Default constructor.
Definition: parabol.h:52
double eval(const double x) const
Evaluate the function.
Definition: parabol.h:66
double a() const
Definition: parabol.h:32
void put_c(const double fc)
Definition: parabol.h:45
double determinant() const
Definition: parabol.h:72
Definition: BGMesh.cpp:5
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:36