要配置一个库Eigen库
链接:https://pan.baidu.com/s/1AofB13zldSq1fT_lKMGf6g
提取码:wqcc
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <complex>
#include <cmath>
#include <math.h>
#include <cfloat>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
double real_x1 = 0.0;
double real_x2 = 0.0;
double real_x3 = 0.0;
double imag_y1 = 0.0;
double imag_y2 = 0.0;
double imag_y3 = 0.0;
int sign = 0;
int one_three(double a, double b, double c, double d);
void one_Two(float a, float b, float c,float C, float E, float D);
void quadratic2quartic(Eigen::Matrix<double, 6, 1>& _par1,
Eigen::Matrix<double, 6, 1>& _par2,
Eigen::Matrix<double, 5, 1>& _y2x_par,
Eigen::Matrix<std::complex<double>, 5, 1>& _quartic_par)
{
double A, B, C, D, E;
double a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2;
a1 = _par1[0];
b1 = _par1[1];
c1 = _par1[2];
d1 = _par1[3];
e1 = _par1[4];
f1 = _par1[5];
// std::cout << a1 << " " << b1 << " " << c1 << " " << d1 << " " << e1 << " " << f1 << std::endl;
a2 = _par2[0];
b2 = _par2[1];
c2 = _par2[2];
d2 = _par2[3];
e2 = _par2[4];
f2 = _par2[5];
// std::cout << a2 << " " << b2 << " " << c2 << " " << d2 << " " << e2 << " " << f2 << std::endl;
A = a1 * c2 - c1 * a2;
B = b1 * c2 - c1 * b2;
C = d1 * c2 - c1 * d2;
D = e1 * c2 - c1 * e2;
E = f1 * c2 - c1 * f2;
_y2x_par << A, B, C, D, E;
// std::cout << "A-E: \n";
// std::cout << A << " " << B << " " << C <<" " << D << " " << E << std::endl;
double M0, M1, M2, M3, M4;
M4 = a1 * B * B - b1 * A * B + c1 * A * A;
M3 = 2 * a1 * B * D - b1 * A * D - b1 * B * C + 2 * c1 * A * C + d1 * B * B - e1 * A * B;
M2 = a1 * D * D - b1 * C * D - b1 * B * E + c1 * C * C + 2 * c1 * A * E + 2 * d1 * B * D - e1 * A * D - e1 * B * C + f1 * B * B;
M1 = -b1 * D * E + 2 * c1 * C * E + d1 * D * D - e1 * C * D - e1 * B * E + 2 * f1 * B * D;
M0 = c1 * E * E - e1 * D * E + f1 * D * D;
// std::cout << "m4-m0: \n";
// std::cout << M4 << " " << M3 << " " << M2 << " " << M1 << " " << M0 << std::endl;
//
// 解一元四次方程
if (M4!=0.0)
{
double b, c, d, e;
b = M3 / M4;
c = M2 / M4;
d = M1 / M4;
e = M0 / M4;
_quartic_par << 1.0, b, c, d, e;
sign = 1;
}
// 解一元三次方程
else if (M4 == 0.0&&M3!=0.0)
{
if (one_three(M3, M2, M1, M0)