21#ifndef LIBMV_NUMERIC_POLY_H_
22#define LIBMV_NUMERIC_POLY_H_
39template <
typename Real>
41 Real q = a * a - 3 *
b;
42 Real r = 2 * a * a * a - 9 * a *
b + 27 * c;
50 Real CR2 = 729 * r * r;
51 Real CQ3 = 2916 * q * q * q;
53 if (
R == 0 && Q == 0) {
55 *x0 = *x1 = *x2 = -a / 3;
58 }
else if (CR2 == CQ3) {
67 *x0 = -2 * sqrtQ - a / 3;
73 *x2 = 2 * sqrtQ - a / 3;
77 }
else if (CR2 < CQ3) {
80 Real sqrtQ3 = sqrtQ * sqrtQ * sqrtQ;
81 Real theta = acos(
R / sqrtQ3);
82 Real
norm = -2 * sqrtQ;
83 *x0 =
norm *
cos(theta / 3) - a / 3;
99 Real sgnR = (
R >= 0 ? 1 : -1);
100 Real A = -sgnR *
pow(
fabs(
R) +
sqrt(R2 - Q3), 1.0 / 3.0);
107template <
typename Real>
109 if (coeffs[0] == 0.0) {
114 Real a = coeffs[2] / coeffs[3];
115 Real
b = coeffs[1] / coeffs[3];
116 Real c = coeffs[0] / coeffs[3];
118 a,
b, c, solutions + 0, solutions + 1, solutions + 2);
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
local_group_size(16, 16) .push_constant(Type b
pow(value.r - subtrahend, 2.0)") .do_static_compilation(true)
ccl_device_inline float2 fabs(const float2 a)
ccl_device_inline float3 cos(float3 v)
int SolveCubicPolynomial(Real a, Real b, Real c, Real *x0, Real *x1, Real *x2)