本文主要是介绍图像处理;C++求已知两直线方程交点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
经过图像处理,得到两直线方程,求两直线交点;
直线的一般方程为F(x) = ax + by + c = 0。既然我们已经知道直线的两个点,假设为(x0,y0), (x1, y1),那么可以得到a = y0 – y1, b = x1 – x0, c = x0y1 – x1y0。
因此我们可以将两条直线分别表示为
F0(x) = a0*x + b0*y + c0 = 0, F1(x) = a1*x + b1*y + c1 = 0
那么两条直线的交点应该满足
a0*x + b0*y +c0 = a1*x + b1*y + c1
由此可推出
x = (b0*c1 – b1*c0)/D
y = (a1*c0 – a0*c1)/D
D = a0*b1 – a1*b0, (D为0时,表示两直线平行)
void GetCrossPoint(float A1, float B1, float A3, float B3,int count,vector<Point2d>& cross_Pt)
{ int L1x0 = 1, L1x1 = 500, L3x0 = 1, L3x1 = 500; //像素坐标X上随便取两点float L1y0 = A1*L1x0 + B1; //根据已知直线方程求对应的Y值float L1y1 = A1*L1x1 + B1;float L3y0 = A3*L3x0 + B3;float L3y1 = A3*L3x1 + B3;float a1 = L1y0 - L1y1;float b1 = L1x1 - L1x0;float c1 = L1x0*L1y1 - L1x1*L1y0;float a3 = L3y0 - L3y1;float b3 = L3x1 - L3x0;float c3 = L3x0*L3y1 - L3x1*L3y0;float D = a1*b3 - a3*b1;double x = (b1*c3 - b3*c1) / D;double y = (a3*c1 - a1*c3) / D;Point2d tmp_pt;tmp_pt.x = x;tmp_pt.y = y;cross_Pt.push_back(tmp_pt);
}
这篇关于图像处理;C++求已知两直线方程交点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!