Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
parabola.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 a quadratic equation.
18
19class Parabola {
20 public:
21 double a() const { return da; }
22 double b() const { return db; }
23 double c() const { return dc; }
24 void put_a(const double fa) {
25 da = fa;
26 s_det = 0;
27 s_dxzero = 0;
28 }
29 void put_b(const double fb) {
30 db = fb;
31 s_det = 0;
32 s_dxzero = 0;
33 }
34 void put_c(const double fc) {
35 dc = fc;
36 s_det = 0;
37 s_dxzero = 0;
38 }
39
40 /// Default constructor.
41 Parabola() = default;
42 /// Constructor from coefficients.
43 Parabola(double fa, double fb, double fc)
44 : da(fa), db(fb), dc(fc) {}
45 /// Constructor from three points.
46 Parabola(double x[3], double y[3]);
47 /// Constructor from three points.
48 /// At the third one, the derivative of the function is supplied instead of
49 /// the function.
50 Parabola(double x[3], double y[3], int);
51 /// Constructor from three points.
52 Parabola(double x1, double x2, double x3, double y1, double y2, double y3);
53
54 /// Copy constructor.
55 Parabola(const Parabola& f);
56 /// Copy assignment operator.
57 Parabola& operator=(const Parabola& p) = default;
58
59 /// Evaluate the function.
60 double eval(const double x) const { return da * x * x + db * x + dc; }
61
62 // Returns number of solutions. First is the least.
63 int find_zero(double xzero[2]) const;
64 double find_maxmin();
65
66 double determinant() const {
67 const Parabola& t = (*this);
68 if (s_det == 0) {
69 t.s_det = 1;
70 t.det = db * db - 4 * da * dc;
71 }
72 return det;
73 }
74
75 private:
76 double da = 0., db = 0., dc = 0.;
77 mutable int s_det = 0;
78 mutable double det = 0.;
79 mutable int s_dxzero = 0;
80 mutable int qdxzero = 0;
81 mutable double dxzero[2];
82};
83
84std::ostream& operator<<(std::ostream& file, const Parabola& f);
85}
86
87#endif
Solution of a quadratic equation.
Definition parabola.h:19
void put_b(const double fb)
Definition parabola.h:29
Parabola(double fa, double fb, double fc)
Constructor from coefficients.
Definition parabola.h:43
void put_c(const double fc)
Definition parabola.h:34
void put_a(const double fa)
Definition parabola.h:24
double c() const
Definition parabola.h:23
double eval(const double x) const
Evaluate the function.
Definition parabola.h:60
Parabola & operator=(const Parabola &p)=default
Copy assignment operator.
int find_zero(double xzero[2]) const
Definition parabola.cpp:189
double determinant() const
Definition parabola.h:66
double a() const
Definition parabola.h:21
Parabola()=default
Default constructor.
double find_maxmin()
Definition parabola.cpp:234
double b() const
Definition parabola.h:22
Definition BGMesh.cpp:6
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition BGMesh.cpp:37