1 #ifndef MATH_CubicPolynom_HPP
2 #define MATH_CubicPolynom_HPP
8 int& n, T solutions[3]) {
12 MATH_QuadraticPolynom::solve<T>(b,c,d,n,solutions);
19 tReal p=c/a-b*b/(3*a*a);
20 tReal q=(b/(27*a))*(2*b*b/(a*a)-9*c/a)+d/a;
22 tReal delta=-(4*p*p*p+27*q*q);
25 delta=sqrt(-delta/27);
27 if (u>0) u=pow(u,1./3.);
28 else u=-pow(-u,1./3.);
31 if (v>0) v=pow(v,1./3.);
32 else v=-pow(-v,1./3.);
34 solutions[0]=(T)(u+v+dx);
38 tReal theta=acos((-q/2)*sqrt(27/(-p*p*p)))/3.;
40 for (
int k=0;k<3;k++) {
41 solutions[k]=(T) (r*cos(theta+2*k*M_PI/3)+dx);
43 if (solutions[0]>solutions[1]) std::swap(solutions[0],solutions[1]);
44 if (solutions[1]>solutions[2]) {
45 std::swap(solutions[1],solutions[2]);
46 if (solutions[0]>solutions[1]) std::swap(solutions[0],solutions[1]);
50 if ((p==0) && (q==0)) {
55 solutions[0]=(T) dx+3*q/p;
56 solutions[1]=(T) dx-1.5*q/p;
57 if (solutions[0]>solutions[1]) std::swap(solutions[0],solutions[1]);
static void solve(const tReal &a, const tReal &b, const tReal &c, const tReal &d, int &n, T solutions[3])
Definition: MATH_CubicPolynom.hpp:7
#define tReal
Definition: types.h:18