22 #include "../../include/ecl/geometry/polynomial.hpp" 65 intercepts << -1.0*b/a;
80 double discriminant = b*b - 4*a*c;
81 if ( discriminant > 0.0 ) {
83 intercepts << (-b + sqrt(discriminant))/(2*a), (-b - sqrt(discriminant))/(2*a);
84 }
else if ( discriminant == 0.0 ) {
86 intercepts << -b/(2*a);
108 double p = (3*a*c - b*b)/(3*a*a);
109 double q = (2*b*b*b - 9*a*b*c + 27*a*a*d)/(27*a*a*a);
110 double discriminant = p*p*p/27 + q*q/4;
114 double shift = -b/(3*a);
115 if ( ( p == 0 ) && ( q == 0 ) ) {
117 intercepts.resize(1);
120 }
else if ( p == 0 ) {
123 intercepts.resize(1);
125 }
else if ( q == 0 ) {
128 intercepts.resize(3);
129 intercepts << shift, sqrt(-1*p) + shift, -sqrt(-1*p) + shift;
130 }
else if ( discriminant == 0 ) {
133 intercepts.resize(2);
134 intercepts << 3*q/p + shift, (-3*q)/(2*p) + shift;
135 }
else if ( discriminant >= 0 ) {
139 intercepts.resize(1);
140 intercepts << u + v + shift;
145 double t_1 = 2.0*sqrt(-p/3.0)*cos((1.0/3.0)*acos( ((3.0*q)/(2.0*p)) * sqrt(-3.0/p)));
146 double t_2 = 2.0*sqrt(-p/3.0)*cos((1.0/3.0)*acos(( (3.0*q)/(2.0*p)) * sqrt(-3.0/p))-(2.0*
ecl::pi)/3.0);
147 double t_3 = 2.0*sqrt(-p/3.0)*cos((1.0/3.0)*acos(( (3.0*q)/(2.0*p)) * sqrt(-3.0/p))-(4.0*
ecl::pi)/3.0);
148 intercepts.resize(3);
149 intercepts << t_1+shift, t_2+shift, t_3+shift;
156 double a_0 =
f.coefficients()[0];
157 double b_0 =
f.coefficients()[1];
158 double a_1 = g.coefficients()[0];
159 double b_1 = g.coefficients()[1];
161 last_operation_failed =
true;
164 point.x((a_0 - a_1)/(b_1 - b_0));
165 point.y(
f(point.x()));
171 const double& x_begin,
const double& x_end,
const LinearFunction &
function) {
172 double max =
function(x_begin);
173 double test_max =
function(x_end);
174 if ( test_max > max ) {
181 const double& x_begin,
const double& x_end,
const CubicPolynomial& cubic) {
183 double max = cubic(x_begin);
184 double test_max = cubic(x_end);
185 if ( test_max > max ) {
189 double a = 3*coefficients[3];
190 double b = 2*coefficients[2];
191 double c = coefficients[1];
194 if ( ( root > x_begin ) && ( root < x_end ) ) {
195 test_max = cubic(root);
196 if ( test_max > max ) {
201 double sqrt_term = b*b-4*a*c;
202 if ( sqrt_term > 0 ) {
203 double root = ( -b + sqrt(b*b-4*a*c))/(2*a);
204 if ( ( root > x_begin ) && ( root < x_end ) ) {
205 test_max = cubic(root);
206 if ( test_max > max ) {
210 root = ( -b - sqrt(b*b-4*a*c))/(2*a);
211 if ( ( root > x_begin ) && ( root < x_end ) ) {
212 test_max = cubic(root);
213 if ( test_max > max ) {
223 const double& x_begin,
const double& x_end,
const LinearFunction &
function) {
224 double min =
function(x_begin);
225 double test_min =
function(x_end);
226 if ( test_min < min ) {
233 const double& x_begin,
const double& x_end,
const CubicPolynomial& cubic) {
235 double min = cubic(x_begin);
236 double test_min = cubic(x_end);
237 if ( test_min < min ) {
241 double a = 3*coefficients[3];
242 double b = 2*coefficients[2];
243 double c = coefficients[1];
246 if ( ( root > x_begin ) && ( root < x_end ) ) {
247 test_min = cubic(root);
248 if ( test_min < min ) {
253 double sqrt_term = b*b-4*a*c;
254 if ( sqrt_term > 0 ) {
255 double root = ( -b + sqrt(b*b-4*a*c))/(2*a);
256 if ( ( root > x_begin ) && ( root < x_end ) ) {
257 test_min = cubic(root);
258 if ( test_min < min ) {
262 root = ( -b - sqrt(b*b-4*a*c))/(2*a);
263 if ( ( root > x_begin ) && ( root < x_end ) ) {
264 test_min = cubic(root);
265 if ( test_min < min ) {
Primary template functor for the maximum of a continuous function.
Embedded control libraries.
#define ecl_throw(exception)
Primary template functor for the roots of a function (x-axis intercepts).
#define ecl_throw_decl(exception)
X axis intercepts for linear functions.
Primary template functor for polynomial division.
Primary template functor for the intersection of like functions.
Coefficients & coefficients()
Handle to the coefficient array, use to initialise the polynomial.
Scalar cube_root(const Scalar &x)
bool isApprox(const Scalar &x, const OtherScalar &y, typename numeric_limits< Scalar >::Precision precision=numeric_limits< Scalar >::dummy_precision)
Generic container storing a cartesian point of dimension N.
void f(int i) ecl_debug_throw_decl(StandardException)
Representation of a polynomial function of n-th degree.
Primary template functor for the minimum of a continuous function.