TypeIIRMLPolynomial.cpp
Go to the documentation of this file.
1 // ---------------------- Doxygen info ----------------------
40 // ----------------------------------------------------------
41 // For a convenient reading of this file's source code,
42 // please use a tab width of four characters.
43 // ----------------------------------------------------------
44 
45 
46 #include <TypeIIRMLPolynomial.h>
47 #include <TypeIIRMLMath.h>
48 
49 
50 //************************************************************************************
51 // Constructor()
52 
54 {
55  a0 = 0.0;
56  a1 = 0.0;
57  a2 = 0.0;
58  DeltaT = 0.0;
59  Degree = 0;
60 }
61 
62 
63 //************************************************************************************
64 // Destructor()
65 
67 {}
68 
69 
70 //************************************************************************************
71 // SetCoefficients()
72 // f(t) = a_2 * (t - DeltaT)^2 + a_1 * (t - DeltaT) + a_0
73 
75  , const double &Coeff1
76  , const double &Coeff0
77  , const double &Diff)
78 {
79  a0 = Coeff0;
80  a1 = Coeff1;
81  a2 = Coeff2;
82  DeltaT = Diff;
83 
84  if (a2 != 0.0)
85  {
86  Degree = 2;
87  return;
88  }
89 
90  if (a1 != 0.0)
91  {
92  Degree = 1;
93  return;
94  }
95 
96  Degree = 0;
97  return;
98 }
99 
100 
101 
102 //************************************************************************************
103 // GetCoefficients()
104 
106  , double *Coeff1
107  , double *Coeff0
108  , double *Diff ) const
109 {
110  *Coeff2 = this->a2;
111  *Coeff1 = this->a1;
112  *Coeff0 = this->a0;
113  *Diff = this->DeltaT;
114 
115  return;
116 }
117 
118 
119 
120 //*******************************************************************************************
121 // CalculateValue()
122 // calculates f(t)
123 
125 {
126  return( ((Degree == 2)?
127  (a2 * (t - DeltaT) * (t - DeltaT) + a1 * (t - DeltaT) + a0):
128  ((Degree == 1)?
129  (a1 * (t - DeltaT) + a0):
130  (a0))));
131 }
132 
133 
134 //*******************************************************************************************
135 // CalculateRoots()
136 
138  , double *Root1
139  , double *Root2) const
140 {
141  if (this->Degree == 2)
142  {
143  double b0 = this->a0 / this->a2
144  , b1 = this->a1 / this->a2
145  , SquareRootTerm = 0.25 * pow2(b1) - b0;
146 
147  if (SquareRootTerm < 0.0)
148  {
149  // only complex roots
150 
151  *Root1 = 0.0 ;
152  *Root2 = 0.0 ;
153  *NumberOfRoots = 0 ;
154  }
155  else
156  {
157  // Polynomial of degree two: x^2 + b1 x + b2 = 0
158 
159  SquareRootTerm = TypeIIRMLMath::RMLSqrt(SquareRootTerm);
160 
161  *Root1 = - 0.5 * b1 + SquareRootTerm + this->DeltaT;
162  *Root2 = - 0.5 * b1 - SquareRootTerm + this->DeltaT;
163  *NumberOfRoots = 2 ;
164  }
165  return;
166  }
167 
168  if (this->Degree == 1)
169  {
170  *Root1 = - this->a0 / this->a1 + this->DeltaT;
171  *Root2 = 0.0 ;
172  *NumberOfRoots = 1 ;
173  return;
174  }
175 
176  if (this->Degree == 0)
177  {
178  *Root1 = 0.0 ;
179  *Root2 = 0.0 ;
180  *NumberOfRoots = 0 ;
181  }
182 
183  return;
184 }
185 
double a0
Parameter of the polynomial function .
unsigned int Degree
Positive integer number that defines the degree of the current polynomial.
TypeIIRMLPolynomial(void)
Constructor of the class TypeIIRMLPolynomial.
double DeltaT
Parameter of the polynomial function .
Header file for functions and definitions of constant values and macros.
double RMLSqrt(const double &Value)
Calculates the real square root of a given value. If the value is negative a value of almost zero wil...
Header file for the class TypeIIRMLMath::TypeIIRMLPolynomial and the struct TypeIIRMLMath::MotionPoly...
#define pow2(A)
A to the power of 2.
void SetCoefficients(const double &Coeff2, const double &Coeff1, const double &Coeff0, const double &Diff)
Sets the coefficients of the polynomial object.
~TypeIIRMLPolynomial(void)
Destructor of the class TypeIIRMLPolynomial.
double a1
Parameter of the polynomial function .
double a2
Parameter of the polynomial function .
void CalculateRealRoots(unsigned int *NumberOfRoots, double *Root1, double *Root2) const
Calculates the real roots of the polynomial specified by the attributes of this object.
void GetCoefficients(double *Coeff2, double *Coeff1, double *Coeff0, double *Diff) const
Returns the coefficients of the polynomial object.
double CalculateValue(const double &t) const
Calculates the function value at of the polynomial specified by the attributes of this object...


libreflexxestype2
Author(s):
autogenerated on Sat Nov 21 2020 03:17:34