kornia.geometry.solvers#

Module containing various geometrical solvers/optimizers.

Polynomial Solvers#

kornia.geometry.solvers.solve_quadratic(coeffs)[source]#

Solve given quadratic equation.

The function takes the coefficients of quadratic equation and returns the real roots.

\[coeffs[0]x^2 + coeffs[1]x + coeffs[2] = 0\]
Parameters:

coeffs (Tensor) – The coefficients of quadratic equation :(B, 3)

Return type:

Tensor

Returns:

A tensor of shape (B, 2) containing the real roots to the quadratic equation.

Example

>>> coeffs = torch.tensor([[1., 4., 4.]])
>>> roots = solve_quadratic(coeffs)

Note

In cases where a quadratic polynomial has only one real root, the output will be in the format [real_root, 0]. And for the complex roots should be represented as 0. This is done to maintain a consistent output shape for all cases.

kornia.geometry.solvers.solve_cubic(coeffs)[source]#

Solve given cubic equation.

The function takes the coefficients of cubic equation and returns the real roots.

\[coeffs[0]x^3 + coeffs[1]x^2 + coeffs[2]x + coeffs[3] = 0\]
Parameters:

coeffs (Tensor) – The coefficients cubic equation : (B, 4)

Return type:

Tensor

Returns:

A tensor of shape (B, 3) containing the real roots to the cubic equation.

Example

>>> coeffs = torch.tensor([[32., 3., -11., -6.]])
>>> roots = solve_cubic(coeffs)

Note

In cases where a cubic polynomial has only one or two real roots, the output for the non-real roots should be represented as 0. Thus, the output for a single real root should be in the format [real_root, 0, 0], and for two real roots, it should be [real_root_1, real_root_2, 0].