38 #ifndef FCL_NARROWPHASE_DETAIL_POLYSOLVER_INL_H 39 #define FCL_NARROWPHASE_DETAIL_POLYSOLVER_INL_H 74 return solveLinear(c, s);
77 p = c[1] / (2.0 * c[2]);
102 template <
typename S>
106 S sub, A, B, C, sq_A, p, q, cb_p, D;
107 const S ONE_OVER_THREE = 1 / 3.0;
108 const S PI = 3.14159265358979323846;
112 return solveQuadric(c, s);
121 p = (-ONE_OVER_THREE * sq_A + B) * ONE_OVER_THREE;
122 q = 0.5 * (2.0 / 27.0 * A * sq_A - ONE_OVER_THREE * A * B + C);
150 S phi = ONE_OVER_THREE * acos(-q / sqrt(-cb_p));
151 S t = 2.0 * sqrt(-p);
153 s[1] = -t * cos(phi + PI / 3.0);
154 s[2] = -t * cos(phi - PI / 3.0);
161 S u = cbrt(sqrt_D + fabs(q));
171 sub = ONE_OVER_THREE * A;
172 for(i = 0; i < num; i++)
178 template <
typename S>
181 return (v < getNearZeroThreshold()) && (v > -getNearZeroThreshold());
185 template <
typename S>
188 return std::pow(v, 1.0 / 3.0);
192 template <
typename S>
static int solveQuadric(S c[3], S s[2])
Solve a quadratic function with coefficients c, return roots s and number of roots.
static bool isZero(S v)
Check whether v is zero.
static int solveLinear(S c[2], S s[1])
Solve a linear equation with coefficients c, return roots s and number of roots.
static int solveCubic(S c[4], S s[3])
Solve a cubic function with coefficients c, return roots s and number of roots.
static constexpr S getNearZeroThreshold()
static bool cbrt(S v)
Compute v^{1/3}.
template class FCL_EXPORT PolySolver< double >