# kornia.geometry.solvers¶

Module containing various geometrical solvers/optimizers.

## Polynomial Solvers¶

kornia.geometry.solvers.solve_quadratic(coeffs)

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)

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].

kornia.geometry.solvers.multiply_deg_one_poly(a, b)

Multiply two polynomials of the first order [@nister2004efficient].

Parameters:

a (Tensor) – a first order polynomial for variables $$(x,y,z,1)$$. b: a first order polynomial for variables $$(x,y,z,1)$$.

Return type:

Tensor

Returns:

degree 2 poly with the order $$(x^2, x*y, x*z, x, y^2, y*z, y, z^2, z, 1)$$.

kornia.geometry.solvers.multiply_deg_two_one_poly(a, b)

Multiply two polynomials a and b of degrees two and one [@nister2004efficient].

Parameters:
Return type:

Tensor

Returns:

a third degree poly for variables, $$(x^3, y^3, x^2*y, x*y^2, x^2*z, x^2, y^2*z, y^2, x*y*z, x*y, x*z^2, x*z, x, y*z^2, y*z, y, z^3, z^2, z, 1)$$.

kornia.geometry.solvers.determinant_to_polynomial(A)

Represent the determinant by the 10th polynomial, used for 5PC solver [@nister2004efficient].

Parameters:

A (Tensor) – Tensor $$(*, 3, 13)$$.

Return type:

Tensor

Returns:

a degree 10 poly, representing determinant (Eqn. 14 in the paper).