从旋转矩形中计算出边界框坐标

82

我有一个矩形左上角点的坐标,以及它的宽度、高度和旋转角度从0到180度和从-0到-180度。

我想要获取实际包围该矩形的框的边界坐标。

有什么简单方法来计算包围框的坐标呢?

  • 最小y值、最大y值、最小x值、最大x值吗?

点A不一定在最小y边界上,它可以在任何位置。

如果需要,我可以使用AS3中的矩阵变换工具包。


1
图片无法显示..(图片上写着:点击发现Imageshack)!!! - Pratham
对不起,我的错。不知道能否从谷歌存档或其他地方找回它。 - coulix
1
什么是A点? - Xhark
12个回答

0

我使用了区域来首先旋转矩形,然后使用旋转后的区域来检测该矩形。

        r = new Rectangle(new Point(100, 200), new Size(200, 200));         
        Color BorderColor = Color.WhiteSmoke;
        Color FillColor = Color.FromArgb(66, 85, 67);
        int angle = 13;
        Point pt = new Point(r.X, r.Y);
        PointF rectPt = new PointF(r.Left + (r.Width / 2),
                               r.Top + (r.Height / 2));
       //declare myRegion globally 
        myRegion = new Region(r);

        // Create a transform matrix and set it to have a 13 degree

        // rotation.
        Matrix transformMatrix = new Matrix();
        transformMatrix.RotateAt(angle, pt);

        // Apply the transform to the region.
        myRegion.Transform(transformMatrix);
        g.FillRegion(Brushes.Green, myRegion);
        g.ResetTransform();

现在开始检测那个矩形

        private void panel_MouseMove(object sender, MouseEventArgs e)
    {


        Point point = e.Location;
        if (myRegion.IsVisible(point, _graphics))
        {
            // The point is in the region. Use an opaque brush.
            this.Cursor = Cursors.Hand;
        }
        else {
            this.Cursor = Cursors.Cross;
        }

    }

0

我不确定我理解了,但是一个复合变换矩阵将为您提供所有相关点的新坐标。如果您认为矩形可能在变换后溢出可成像区域,请应用剪切路径。

如果您对矩阵的确切定义不熟悉,请查看此处


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接