foxes.utils.cubic_roots(a0, a1, a2, a3=None)[source]

Calculate real roots of polynomials of degree 3.

Convention: f(x) = a[3]*x**3 + a[2]*x**2 + a[1]*x + a[0]

In contrast to numpy’s “root” function this works fast for an array of polynomials, so you spare yourself looping over them.

Source: https://github.com/opencv/opencv/blob/master/modules/calib3d/src/polynom_solver.cpp

Parameters

a0: numpy.ndarray

The coefficients a[0]

a1: numpy.ndarray

The coefficients a[1]

a2: numpy.ndarray

The coefficients a[2]

a3: numpy.ndarray

The coefficients a[3], or None for ones

Returns

roots: numpy.ndarray

The real roots of the polynomial, shape: (n_a0, 3). If one root only the two last columns will be np.nan