CvPoint GetTwoLineCrossPoint(const int& x1, const int& y1, const int& x2, const int& y2, const int& x3, const int& y3, const int& x4, const int& y4) { //第一条直线的参数 double a0 = y1 - y2; double b0 = x2 - x1; double c0 = x1 * y2 - x2 * y1; //第二条直线的参数 double a1 = y3 - y4; double b1 = x4 - x3; double c1 = x3 * y4 - x4 * y3; //求交点 double D = a0 * b1 - a1 * b0; if (fabs(D) < 0.00001) { return cvPoint(-1, -1); } CvPoint p; p.x=(int)((b0 * c1 - b1 * c0) / D); p.y=(int)((c0 * a1 - c1 * a0) / D); return p; }
时间: 2024-10-04 11:04:43