如何正确地从交点到球的中心绘制轨迹线?

时间:2019-04-29 07:43:50

标签: c++ line opencv3.0 intersection

我目前正在处理斯诺克轨迹项目。我已成功计算出球杆和球之间的交点公式。

我得到的线是在图像帧中绘制的,而不是从第一个交点(提示线和球的外圈之间)到球的中心绘制的,而是从球的中心反向绘制的到交叉点。

因此,这种情况使球投射运动的方式出错了。

这是发生交集时的公式

else
{
    circleLineIntercept = true;
    cout << "intercept happen" << endl;
    float mu = (-b + sqrt(b*b - 4 * a*c)) / (2 * a);

    //The intersection points = (ix,iy)
        //This calculate for first intersection

    float ix1 = pt1.x + mu * (dx);
    float iy1 = pt1.y + mu * (dy);

        //This calculate for second intersection
    mu = (-b + sqrt(b*b - 4 * a*c)) / (2 * a);
    float ix2 = pt2.x + mu * (dx);
    float iy2 = pt2.y + mu * (dy);




这基本上是绘制零件的代码。

基本上,我只是得到交叉点,并将其绘制到中心球上。但是反之亦然,这条线从中心到交点。


if (flag == true)
{
    Point intercept(intx, inty);
    Point first_point_intercept(ix1, iy1);
    Point second_point_intercept(ix2, iy2);              
    line(imgFrame,first_point_intercept,center, Scalar(255, 0, 255), 1,8);
}

0 个答案:

没有答案