计算斜着椭圆内某个点到边距离(验证ok)

        sPoint center;
        center.x = sLRpInfo.rdOut.x; center.y = sLRpInfo.rdOut.y;
        float a = sLRpInfo.rdOut.a;  // 长轴半径
        float b = sLRpInfo.rdOut.b; // 短轴半径
        float theta = (360.0 - sLRpInfo.rdOut.fAngle) * CV_PI / 180.0f; // 旋转角度,转换为弧度
        float fddtoCen = 0;
        for (i = 0;i < nDftNum;i++)
        {
            rdFit = A_RoundFitting(v_FitRound.at(i), 0, v_FitRound.at(i).size());
            rdFit.x += roi.l; rdFit.y += roi.t;
            sLRpInfo.rdFeaFit[i] = rdFit;
            if (2 * rdFit.r > sLRpInfo.fGetMaxMinRd[1])sLRpInfo.fGetMaxMinRd[1] = 2 * rdFit.r;
            if (2 * rdFit.r < sLRpInfo.fGetMaxMinRd[0])sLRpInfo.fGetMaxMinRd[0] = 2 * rdFit.r;

            if (sLRpInfo.bArith[5])
            {
                float x_prime = (rdFit.x - center.x) * cos(theta) + (rdFit.y - center.y) * sin(theta);
                float y_prime = -(rdFit.x - center.x) * sin(theta) + (rdFit.y - center.y) * cos(theta);

                // 2. 计算参数角 alpha
                float alpha = atan2(y_prime, x_prime);
                if (alpha < 0) alpha += 2 * CV_PI; // 确保 alpha 在 0 到 2π 之间

                // 3. 计算椭圆边界点
                float x_ellipse = a * cos(alpha);
                float y_ellipse = b * sin(alpha);

                // 4. 旋转回全局坐标系
                sLRpInfo.ptOffArcEdge[i].x = center.x + x_ellipse * cos(theta) - y_ellipse * sin(theta);
                sLRpInfo.ptOffArcEdge[i].y = center.y + x_ellipse * sin(theta) + y_ellipse * cos(theta);

                // 计算边界点到中心的距离
                fddtoCen = A_GetPointDistence(sLRpInfo.ptOffArcEdge[i], center);

                if (fddtoCen > sLRpInfo.fGetMaxMinToArc[1])
                    sLRpInfo.fGetMaxMinToArc[1] = fddtoCen;
                if (fddtoCen < sLRpInfo.fGetMaxMinToArc[0])
                    sLRpInfo.fGetMaxMinToArc[0] = fddtoCen;
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值